ImageMagick -resize: Resize and Thumbnail
convert in.png -resize 800x600 out.png scales an image to fit a box while preserving aspect ratio.
Resizing is ImageMagick's most common CI use, for thumbnails or responsive asset sets. The geometry suffixes (!, ^, >) control exactly how the box is interpreted.
What it does
-resize <geometry> scales the image to the given geometry. By default it fits within the box keeping aspect ratio; suffixes change that: ! forces exact dimensions, ^ fills (minimum), > only shrinks larger images, < only enlarges smaller ones. -thumbnail is like -resize but strips metadata and is faster for small outputs.
Common usage
# fit within 800x600 (aspect preserved)
convert in.png -resize 800x600 out.png
# exact size, ignore aspect ratio
convert in.png -resize 800x600! out.png
# only shrink if larger than 1200px wide
convert in.png -resize 1200x\> out.png
# fast thumbnail (also strips metadata)
convert in.png -thumbnail 200x200 thumb.pngOptions
| Geometry / Flag | What it does |
|---|---|
| WxH | Fit within WxH, preserve aspect ratio |
| WxH! | Force exact WxH, ignore aspect ratio |
| WxH^ | Fill WxH (minimum dimensions), then often -crop |
| WxH> | Shrink only if larger; never enlarge |
| WxH< | Enlarge only if smaller |
| -thumbnail WxH | Resize and strip metadata (faster, smaller) |
In CI
Quote or escape geometry suffixes (\> in bash) so the shell does not treat > as a redirect. Use -thumbnail for icon-sized outputs to keep files small and reproducible.
Common errors in CI
"cache resources exhausted" or "DistributedPixelCache" / "width or height exceeds limit" errors on large images come from ImageMagick's resource limits in policy.xml; raise them with -limit memory 512MiB -limit map 1GiB on the command line or edit /etc/ImageMagick-6/policy.xml. "no images defined" means the output path/format is invalid or the input failed to load. A > interpreted as a shell redirect (empty output, stray file named out.png) means the geometry was not escaped.