Change Canvas Size Of A Batch Of Images

GIMP and Photoshop both have features allowing you to change the canvas size of an image without resizing it. This can be useful for putting a border round your image, cropping out only part of the image, or fitting an image to a certain aspect ratio. Here's how to change the canvas size of a batch of images in one go using the command line tools provided by ImageMagick. ImageMagick is a suite of tools allowing you to manipulate images in masses of different ways from the command line. I use the linux version of this, and also run it under Cygwin on Windows. I believe there is a Windows native version of ImageMagick.

Lets take example below which is in a wide format such as taken by an SLR camera at 300x188 pixels. Say we need to fit this into a standard 4:3 ratio.

Original Image 300x188

Original image before changing canvas size

Mogrify Command

mogrify.exe -background white -extent 300x225 -gravity center image.jpg

New Canvas Size 300x225

Image after changing canvas size

-background white specifies the colour of the new canvas around the edges of the existing image. Replace that with another colour for example if you wanted a coloured border around your image.

-extent 300x225 is the dimensions of the new canvas

-gravity center says where in the new canvas you want the existing image to float.

Replace image.jpg with *.jpg to change the canvas size of all images in the current directory. This will replace all the images, so back them up first! Alternatively, add -path newimages to put the modified images in a new folder, leaving the originals untouched.

Page Updated 13/11/09