| @@ -39,10 +39,12 @@ magick input.png -resize 1920x1080^ -gravity center -extent 1920x1080 output.png | |||
| 39 | 39 | Some examples, could use with any of the above. | |
| 40 | 40 | ||
| 41 | 41 | ```sh | |
| 42 | - | # Resize all jpgs to 60% of their original size | |
| 42 | + | # Resize all jpgs to 60% of their original size, adding `60_` prefix to output name | |
| 43 | 43 | for i in *.jpg; do magick $i -resize 60% "60_$i"; done | |
| 44 | 44 | ||
| 45 | - | # Resize a directory full of wallpapers to overflow and crop, `-backgroun none` to preserve transparency | |
| 45 | + | # Resize a directory full of wallpapers to overflow and crop | |
| 46 | + | # `-backgroun none` to preserve transparency | |
| 47 | + | # renaming with a suffix eg. input.png -> input_1920x1080.png | |
| 46 | 48 | for i in *.png; do magick "$i" -background none -resize 1920x1080^ -gravity center -extent 1920x1080 "${i%.png}_1920x1080.png"; done | |
| 47 | 49 | ``` | |
| 48 | 50 | ||
mag37 / ImageMagick_tricks.md
Last active 1 month ago
mag37 revised this gist 1 month ago · 8bdc35d
1 file changed, 4 insertions, 2 deletions
mag37 revised this gist 1 month ago · 796f3d2
1 file changed, 1 insertion, 1 deletion
| @@ -1,4 +1,4 @@ | |||
| 1 | - | ## Basic resizing with different end | |
| 1 | + | ## Basic resizing with different results | |
| 2 | 2 | ```sh | |
| 3 | 3 | # Resize to fit within 800x600, preserving aspect ratio | |
| 4 | 4 | magick input.png -resize 800x600 output.png | |
mag37 revised this gist 1 month ago · f7da0d7
1 file changed, 45 insertions, 3 deletions
| @@ -1,6 +1,48 @@ | |||
| 1 | + | ## Basic resizing with different end | |
| 2 | + | ```sh | |
| 3 | + | # Resize to fit within 800x600, preserving aspect ratio | |
| 4 | + | magick input.png -resize 800x600 output.png | |
| 5 | + | # 1000x1000 -> 600x600, 1600x1000 -> 800x500 | |
| 6 | + | ||
| 7 | + | # Resize by percentage, rounds to closest integer pixel which can be off compared to exact pixels | |
| 8 | + | magick input.png -resize 50% output.png | |
| 9 | + | # 1000x800 -> 500x400, 800x593 -> 400x297 (half a pixel too high, could distort) | |
| 10 | + | ||
| 11 | + | # Resize to fit 800 height, width will scale to match - move the x to swap | |
| 12 | + | magick input.png -resize x800 output.png | |
| 13 | + | # 200x400 -> 400x800, 1600x1600 -> 800x800 | |
| 14 | + | ||
| 15 | + | # Force exact dimensions, breaking aspect ratio scaling. Escape like this `\!` | |
| 16 | + | magick input.png -resize 1100x800\! output.png | |
| 17 | + | # 1600x900 -> 1100x800 | |
| 18 | + | ||
| 19 | + | # Only shrink larger images, never enlarge smaller. Escape like this `\>` | |
| 20 | + | magick input.png -resize x800\> output.png | |
| 21 | + | # # 200x400 -> 200x400, 1600x1600 -> 800x800 | |
| 22 | + | ||
| 23 | + | # Resize based on smallest fitting dimension, Image will fill and overflow. Useful together with -crop/-extent | |
| 24 | + | magick input.png -resize 800x800^ output.png | |
| 25 | + | # 200x400 -> 800x1600, 1000x2000 -> 800x1600 | |
| 26 | + | ||
| 27 | + | # Resize to fit within size but keep aspect ratio and fill/pad with black | |
| 28 | + | magick input.png -background black -resize 400x400 -gravity center -extent 400x400 output.png | |
| 29 | + | # 800x400 -> 400x400 | |
| 30 | + | # original image will first scale to 400x200 then pad with black top+bottom calculated from center | |
| 31 | + | ||
| 32 | + | # The above example to keep aspect ratio but remove overflow, fill and crop | |
| 33 | + | magick input.png -resize 1920x1080^ -gravity center -extent 1920x1080 output.png | |
| 34 | + | # 1920x1200 -> 1920x1080, 1600x1400 -> 1920x1080 | |
| 35 | + | ||
| 36 | + | ``` | |
| 37 | + | ||
| 1 | 38 | ## Batch resize images | |
| 2 | - | Resize images with ImageMagick, all images in current directory to "resized" subdirectory. | |
| 39 | + | Some examples, could use with any of the above. | |
| 3 | 40 | ||
| 4 | 41 | ```sh | |
| 5 | - | for i in *.jpg; do magick $i -resize 60% ./sized/$i; done | |
| 6 | - | ``` | |
| 42 | + | # Resize all jpgs to 60% of their original size | |
| 43 | + | for i in *.jpg; do magick $i -resize 60% "60_$i"; done | |
| 44 | + | ||
| 45 | + | # Resize a directory full of wallpapers to overflow and crop, `-backgroun none` to preserve transparency | |
| 46 | + | for i in *.png; do magick "$i" -background none -resize 1920x1080^ -gravity center -extent 1920x1080 "${i%.png}_1920x1080.png"; done | |
| 47 | + | ``` | |
| 48 | + | ||
mag37 revised this gist 1 month ago · b4ae0f8
1 file changed, 6 insertions
| @@ -0,0 +1,6 @@ | |||
| 1 | + | ## Batch resize images | |
| 2 | + | Resize images with ImageMagick, all images in current directory to "resized" subdirectory. | |
| 3 | + | ||
| 4 | + | ```sh | |
| 5 | + | for i in *.jpg; do magick $i -resize 60% ./sized/$i; done | |
| 6 | + | ``` | |