ImageMagick Batch Convert Files
I recently shot a wedding for a friend and found myself with a few hundred images in RAW format, of which I processed the handful that I liked. Due to Flickr increasing the maximum file sizes you can upload to 50MB, I went ahead and saved my final results as lossless PNG images.
However, I also wanted to upload the images to a photo printing service that apparently does not accept PNGs as a valid photo file. (stupid AdoramaPix…).
So the question became, how can I batch convert all of the PNG images into JPG images on the windows command line?
I already had ImageMagick installed (and highly recommend it if you ever need to do batch image processing on your machine). So the question now becomes, how can I use IMs convert command to do this?
The answer is right here:
for %f in (*.png) do (convert %f -quality 100 %~nf.jpg)
What a royal PITA it was tracking this down. In a nutshell:
for %f in (*.png)
For each variable (f in my case) in all the files that end in .png in my current directory…
do (convert %f -quality 100
convert the file with a quality of 100…
%~nf.jpg)
and name the output the original file name plus .jpg as an extension. That last bit was a real pain to get right, and required me looking into the Microsoft documentation of FOR.
So, if you happen to be on windows, and have Imagemagick installed - here is the solution to batch converting images in a directory.
Oh, and you can expand the types of images and lump them all together at once. For instance, instead of *.png, you could have told it to do .png and .tif images:
for %f in (*.png *.tif) …
Hopefully this snippet will be useful to some fellow traveler… (relevant xkcd)