2 min read

Batch-converting images

I had a wad of images that I needed to resize from 300dpi and high-resolution jpg to 4.5x6 (or 6x4.5) low resolution at 72 dpi.

First, I installed ImageMagick: sudo aptitude install imagemagick

Then I opened GIMP and determined the pixel width and height of one image. (Image -> Canvas Size). In my case, it was 3264x2448.

Next, I resized the image to the size I wanted. That turned out to be 432x324.

In other words, I wanted my new images to be 0.132352941 of the original image. A quick test told me I was on the right track: convert P4250049.JPG -resize 13.2352941% test.jpg

The first time I did this I forgot the % sign and got a 13x10 pixel image - not exactly what I wanted.

So, on to batch-converting everything in a directory: mkdir ./resized for i in *.JPG; do echo $i convert $i -resize 13.235941% -quality 20 ./resized/$i done

And all my resized images were in the resized directory below the image directory. (Did I mention I wanted to reduce the quality so my images would be smaller too? Yep, that’s what the -quality line does.)