Batch resize images with ImageMagic

Recently I had to reduce the size of many images for uploading  them to a website. Unfortunately I didn’t find any tool like IrfanView on Ubuntu, which I’ve used for such problems in my Windows days.

But there is a much smarter way to batch resize images on Linux. You simply can use the convert command from ImageMagic. To install it, you have to run:

$> sudo apt-get install imagemagick

Thereafter you can use the following command to batch resize all images in the current folder:

$> find . -type f -name "*.jpg" -exec convert {} -resize 50% {}_small.jpg \;

As you can see, it searches for all jpg files in the current folder and executes the convert command for the respective file. All files will shrink by fifty percent. The resized images are stored in new files named after the original one expanded by the suffix _small.

It would also be possible to use the build-in wildcard feature of convert (convert *.jpg -resize …) but that would be more memory exhausting, because it will load all images into memory at once before converting them. The described method above only loads one image simultaneously into memory, which is much more resource-saving.

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.