How to resize product photos in batchs with Mogrify in two steps?

Resize product photos in batches

The following requirement popped up to resize a batch of product photos with various resolutions.

  • Final image size should be 500 x 500px.
  • If the original image is larger it should be resized, for the aspect ratio.
  • If the image width and height differ, the lower side should be filled with white background.
  • The original image should be in the Center of the Final image.
  • Most especially I am not a fan of wasting my time on repetitive works so AUTOMATION was the most important requirement:).

I tried many options but the only stable solution I found was to use the Mogrify tool which comes with the ImageMagic package.

I am using the Linux flavor because in two easy steps we are ready to roll.

Step 1: Installing ImageMagick

I am using Debian derivative OS for this example. If you have any other OS, please use the respective installation command.

sudo apt-get update
sudo apt-get install ImageMagick

Step 2: Resizing images

Upload all of your photos to a folder in the Linux box and open that folder from the CLI.

cd /image_folder
mogrify -resize 500x500 -extent 500x500 -gravity center -background white *.jpg

Note: In my situation, all images were in jpg format but if you have images in various formats please convert all of them to jpg before proceeding.

That's it! :). Download your uploaded images and they should be in the required format by now.

You can do many more things with this amazing tool. Please check the official documentation of Mogrify to learn more.

Don't forget to leave a comment if this was helpful 😊


You are welcome to share your ideas with us in the comments!


Contact Form