How to Scale Image by Percentage in ImageMagick?

This article provides a quick overview and practical guide on how to resize images using percentages rather than fixed pixel dimensions with the ImageMagick convert command. You will learn the exact syntax required, how to maintain or alter aspect ratios, and how to apply these changes across multiple files efficiently.


Understanding the Percentage Syntax

By default, the ImageMagick -resize or -scale geometry argument expects width and height values in pixels. However, you can easily instruct ImageMagick to interpret these numbers as percentages by appending a percent sign (%) to the value.

When you use a percentage, ImageMagick calculates the new dimensions relative to the original image’s width and height.

Basic Scaling Examples

Here is the standard command to scale an image to 50% of its original size:

convert input.jpg -resize 50% output.jpg

If you want to scale the width and height by different percentages, you can specify both dimensions separated by an x:

convert input.jpg -resize 50%x75% output.jpg

Key Differences: -resize vs. -scale

While both flags can use percentages, they handle the underlying pixel manipulation differently:

Maintaining Aspect Ratio

When you provide a single percentage value (like 50%), ImageMagick automatically scales both the width and the height by that amount, perfectly preserving the original aspect ratio.

If you provide two different percentages (like 50%x75%), ImageMagick will still attempt to preserve the aspect ratio within those maximum bounds by default. To force the image to stretch and exactly match unequal percentages, append an exclamation point (!) to the geometry string:

convert input.jpg -resize 50%x75%! output.jpg

Bulk Processing with Mogrify

If you need to scale an entire folder of images by a percentage, using convert in a loop can be tedious. Instead, you can use the mogrify tool, which overwrites the original files or outputs them to a new directory:

mogrify -resize 25% *.png