Batch resize photos using ImageMagick

This will be a quick one. I tend to forget the method of batch photo resize using ImageMagick in Linux.

In some cases I need to resize all files in the directory and change their quality – they should be still good for the web but not take too much space. By trial and error, I come up with this method:

for X in *.jpg; do convert "$X" -resize 2000x2000 -quality 70 "sm-$X"; done

The above works for all jpg files in the directory (but you can change it to work with any other file type). Please note that some of them may not utilize quality parameter.

The resized image will be no bigger than 2000×2000 pixels. The aspect ratio is maintained.

The resized file will have the same name with the “sm-” prefix added.

Leave a Reply

Your email address will not be published. Required fields are marked *