How to Resize Smaller Images in ImageMagick?
When batch processing images, you often want to enlarge smaller
images to a standard size without accidentally shrinking or distorting
your larger files. ImageMagick handles this perfectly using a specific
conditional geometry flag (<) within the
convert or magick command. This article will
show you the exact syntax needed to upscale only the images that fall
below your target dimensions, preventing any unwanted resizing of larger
assets.
The Conditional Resize Command
To instruct ImageMagick to only upscale an image if its dimensions
are smaller than your target size, you append a less-than sign
(<) to the geometry argument.
Here is the standard command structure:
magick convert input.jpg -resize "1920x1080>" output.jpgNote: In newer versions of ImageMagick (v7+), the
convertcommand is deprecated in favor of the unifiedmagickcommand, thoughmagick convertstill works for backwards compatibility.
Why the Backslash or Quotes are Necessary
In most terminal environments (like Linux Bash, macOS Zsh, or Windows
PowerShell), the < character is a special operator used
for input redirection. If you type it plainly, your terminal will throw
a syntax error.
To prevent this, you must “escape” the character or wrap the entire dimension string in quotes. Depending on your operating system, choose one of the following methods:
- Using Quotes (Recommended for all platforms):
magick convert input.jpg -resize "800x600<" output.jpg- Escaping the Character (Linux/macOS terminal):
magick convert input.jpg -resize 800x600\< output.jpgHow ImageMagick Evaluates the Conditions
ImageMagick looks at both the width and the height of your input image and compares them to your target dimensions:
- Proportional Scaling: By default, ImageMagick
maintains the original aspect ratio. If you specify
"1000x1000<", a500x400image will be enlarged until the larger dimension hits 1000 pixels. - Strict Dimension Enforcement: If you want to force
the image to stretch and exactly match the dimensions regardless of
aspect ratio, add an exclamation point (
!) before the conditional flag:"1000x1000!<".