Mastering image size and transformations: changing dimensions with resize, scale, and thumbnail, understanding the aspect ratio operators, cropping with crop, and controlling rotation, flip, flop, trim, extent, and placement with gravity.

After mastering format conversion in episode 3 — from PNG to JPEG all the way to WebP, with verification via magick identify — now we move to the second most frequently used capability: resizing and transforming images.
In the real world, almost no system uses images at their original size. Photos become thumbnails, hero images are cropped to a ratio, logos are rotated, and all of that must be consistent across thousands of files. This episode gives you full control over image dimensions, cropping, and orientation.
The -resize option accepts a geometry — a specification of the target size. The simplest forms are a percentage and an exact dimension:
magick sample.png -resize 50% half.png
magick sample.png -resize 800x600 fit.pngWithout additional operators, 800x600 means fit inside the box: the image is scaled to fit inside 800x600 with a fixed aspect ratio — no stretching. This is the behavior most often desired.
-resize becomes far more powerful with operators appended to the end of the geometry:
| Geometry | Meaning |
|---|---|
800x600 | Fit inside the box, fixed aspect ratio |
800x600^ | Fill the minimum box, fixed ratio, can be cropped |
800x600! | Force exact dimensions, ratio can change |
50% | Scale by percentage |
800x600> | Shrink only if larger than the target |
800x600< | Enlarge only if smaller than the target |
magick sample.png -resize 800x600^ crop-fit.png
magick sample.png -resize 800x600! stretch.png
magick sample.png -resize 800x600> shrink-if-large.pngNote
Symbol operators like ^ and ! are part of the geometry value, so make sure they are always in a single token without spaces — 800x600^ is correct, 800x600 ^ is wrong. When used inside a shell script, it's a good idea to put the geometry in quotes: "800x600^" — safe from shell interpretation surprises.
-scale and -thumbnail: The Resize Trio| Option | Characteristics |
|---|---|
-resize | High quality, uses resampling filters |
-scale | Faster, no filter — coarser results when enlarging |
-thumbnail | Resize + strip metadata + optimization, designed for web thumbnails |
magick sample.png -resize 320x320 resize.png
magick sample.png -scale 320x320 scale.png
magick sample.png -thumbnail 320x320 thumb.png-thumbnail is a smart shortcut: besides resizing, it discards metadata (an -strip effect) and chooses settings that favor file size. For galleries or article lists that need many small thumbnails, -thumbnail is almost always the best choice.
-crop cuts out part of an image according to the geometry WxH+X+Y — width, height, then the offset from the top-left corner:
magick sample.png -crop 300x200+40+30 cropped.pngmagick sample.png -gravity center -crop 400x300+0+0 centered.png-gravity moves the reference point: with center, an offset of +0+0 means cropping from the center of the image. The combination of -gravity and -crop is the most common way to crop photos to a specific ratio — for example making a 16:9 cover from a landscape or portrait photo.
Important
After -crop, ImageMagick leaves page information (offset) on the image. If that offset is unwanted — for example for a PNG that will be used as a layer — add +repage to reset the page to zero: magick sample.png -gravity center -crop 400x300+0+0 +repage out.png.
| Option | Effect |
|---|---|
-rotate 90 | Rotate 90 degrees clockwise |
-rotate -45 | Rotate 45 degrees counter-clockwise |
-flip | Vertical mirror (top-bottom) |
-flop | Horizontal mirror (left-right) |
magick sample.png -rotate 90 rotated.png
magick sample.png -flip flipped.png
magick sample.png -flop flopped.pngWhen rotating by an angle that isn't a multiple of 90 degrees, the corners of the image form an empty area. Fill that area with -background so it doesn't turn black:
magick sample.png -background white -rotate 45 tilted.png-trim cuts off solid borders at the image edges — very useful for screenshots or images with white padding:
magick sample.png -trim +repage trimmed.pngFor images with colored borders that aren't perfectly solid, add -fuzz for color tolerance:
magick sample.png -fuzz 10% -trim +repage fuzzy-trim.pngThe opposite, -extent, adds canvas — changing the canvas size without scaling the contents:
magick sample.png -gravity center -background black -extent 800x600 canvas.pngThe -gravity center -extent WxH pattern produces a new-canvas image with the contents centered — a technique used to uniformize sizes in a gallery grid without breaking the original aspect ratio.
In this episode 4, you've mastered resize, crop, and transform: changing size with -resize, -scale, and -thumbnail, understanding geometry operators for aspect ratio, cropping with -crop, and controlling orientation and canvas with -rotate, -flip, -flop, -trim, -extent, and -gravity.
The key takeaways:
-resize keeps the aspect ratio by default; the operators ^, !, %, >, < change its behavior.-thumbnail is the best choice for web thumbnails (resize + strip + optimization).-crop with -gravity is the most common pattern for cropping to a specific ratio.-trim removes borders; -extent adds canvas — both are often paired with +repage.magick identify after transformations to verify dimensions.In the next episode 5, we'll cover colorspace, channels, and alpha — converting colors between colorspaces, reducing the palette with -colors and -posterize, adjusting levels, gamma, and contrast, working per channel with -channel, and managing transparency with -alpha, -transparent, and -channel-fx. See you in episode 5!