Resize an image using ImageMagick
|Debian (Etch, Lenny, Squeeze)|
|Ubuntu (Lucid, Maverick, Natty)|
To enlarge or reduce an image using ImageMagick
Suppose that the file
input.png contains a PNG-format image that is 320 by 256 pixels in size. You wish to resize it to 240 by 192 pixels, writing the result to the file
The method described here uses ImageMagick to resize the image. On Debian-based systems, the command-line interface to ImageMagick is provided by the package
apt-get install imagemagick
Resizing is performed using the
-resize operator, which can be invoked as an argument to the
convert input.png -resize 240x192 output.png
By default the aspect ratio of the image is preserved. This is done by reducing either the width or the height of the output by an appropriate amount. If you do not want this to happen, and are prepared to accept the resulting distortion, then you can allow the aspect ratio to change by appending an exclamation mark to the required size. Since this is a shell metacharacter it must be escaped:
convert input.png -resize 240x192\! output.png
There are several other ways in which the output size can be specified, for example as a percentage. See the ImageMagick documentation for further details.
The method described here is not limited to PNG-format images: a large number of other formats are supported, including BMP, GIF, JPEG, PNM and TIFF.
You can check that the result is of the expected size using the
identify command, which is also part of ImageMagick:
The third field of the output is the size in pixels:
output.png PNG 240x192 240x192+0+0 DirectClass 16-bit 100.373kb
If the reported size is different from what was requested then that is probably because one of the dimensions was reduced in order to preserve the aspect ratio. See above for how to override this behaviour.
- ImageMagick v6 Examples -- Resize or Scaling