Resize images on the command line

Today, I needed to copy a large set of images from one of our servers to another. Beside of that, I wanted all of them to be converted - resized to fit my needs. It would be rather painful if I tried to download the whole thing to my local machine first, batch convert the files with some desktop application and then upload it to another server, since just the downloading part would last for at least four hours with the speed of my internet connection. After some research I came up with this solution:


find . -iname '*.jpg' -print0 | xargs -0 mogrify -resize 800x600\>
-monitor -quality 80

With help of the ImageMagick package, this line does all the heavy lifting - it finds all the jpeg images in the directory (and its subdirectories) and then converts them to be no more than 800 by 600 px in size. Mogrify command rewrites the original files, so I needed to make a copy of the images directory.

After that I just used tar and sftp to send the size-reduced image directory to the other server.

Neat.

blog comments powered by Disqus