Tahir Hassan's Blog

My Technical Notes

Sunday, 19 March 2017

Resizing Images using ImageMagick on Windows

ImageMagick is a handy commandline tool for every major platform that can be used to resize images (among its other uses). To install it on Windows, the recommended installer ImageMagick-<version>-Q16-x64-dll.exe worked fine and added magick.exe to the PATH. The installer recommends installing GhostScript for processing PDF and GhostScript, but because we are only using it to resize images, there is no need to install it.

When resizing an image, it is worth thinking about how big you want the resized image to be. To simplify matters, you can think of the resized image as fitting into a rectangle of $n$ by $m$ pixels. When an image is resized, its aspect ratio is maintained, but it has to fit inside this rectangle.

For illustration purposes, we use magick.exe to create a sample image file, wizard.jpg:


magick.exe wizard: wizard.jpg


This image is $480$ by $640$ pixels in size. For simplicity, let's say that we wish to shrink it so that it fits inside a $400$ by $400$ square. Its larger side (vertical), which is $640$, becomes $400$, therefore this side has shrunk by a percentage, $400/640$, which is $.625$. Its horizontal therefore will be $480 * .625$, which is $300$. In summary, the resized image will be $300$ by $400$ pixels in size.

To shrink it to this size, do:


magick.exe wizard.jpg -resize 400x400 resized-wizard.jpg