# Batch processing of image files

I recently had 178 JPEG files that weren’t behaving: Firefox and IE couldn’t display them. GIMP could read them and display them, and a GIMP Save As JPEG (after making no changes) created files that displayed properly in Firefox and IE, but I didn’t want to do that 178 times.

ImageMagick to the rescue. This free program, available for Windows, Mac, and Linux comes with several command line utilities, but the convert one is all I’ve ever needed. It has dozens and dozens of command-line options, but I didn’t even need any to fix these JPEGs. I just converted each to a BMP and then back, like this,

convert myfile.jpg myfile.bmp
convert myfile.bmp myfile.jpg

and then I had a JPEG file that displayed fine in the web browsers. To do this 178 times in Windows, I created a batch file that looked like this

convert %1.jpg %1.bmp
convert %1.bmp %1.jpg

and then used the output of dir /b *.jpg to create a batch file that called the two-line batch file for each image file.

If you need to process batches of images, it’s really worth looking through the command line options it offers, and of course the other ImageMagick utilities as well.

Since writing all that, I’ve found a possibly great new feature of ImageMagick: the ability to add XMP metadata to image files. (XMP is a profile of RDF from Adobe that has a lot of potential; I’ve complained here before about the lack of free command-line tools for adding and extracting XMP metadata from binary files.) Based on my tests and an online problem description, I don’t think this feature works properly yet. If anyone knows how to get ImageMagick or any other free command-line tool to add arbitrary metadata to image and PDF files (and of course, to extract it) please let me know.

By perusio on March 3, 2008 9:51 AM

Hmm, this seems to fit the bill (PDF+image files)

http://www.sno.phy.queensu.ca/~phil/exiftool/

It’s in Perl.

HTH

Thanks Perusio, This looks great! At first http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/XMP.html made me think that it could only handle predefined XMP fields, but http://www.sno.phy.queensu.ca/~phil/exiftool/config.html shows how to define your own metadata fields and store them as XMP. (I’m a big believer in the ability to store arbitrary metadata.) I will certainly be playing with this and reporting back on it.

Dude, that would really really be a case for getting Cygwin, if only so you can do a shell for-loop. (I, of course, download Cygwin first thing onto any Windows computer I have to deal with.)

Hi John,

When I set up a Windows machine, I add Firefox, Emacs, and Cygwin before I even change the desktop wallpaper, but I never looked too closely at Cygwin’s scripting. Looks like I should.\

for f in *.CR2
do
echo Processing $f exiftool -exif:OwnerName="Dave Pawson" -exif:Copyright="Dave Pawson 2008"$f
echo Backup  $f'_'original removed rm$f'_'original
done

exiftool would repay some investigation.

Hello,

in the Imagemagick package there is the command mogrify, using the same syntax as convert, but if you use wildcards in the filename, it will go through all files in the dir… so, for your case\

mogrify -format bmp *.jpg

and then\

mogrify -format jpg *.bmp

\

would have done the same as you showed…

Albin

By Tom Passin on March 3, 2008 11:32 PM

Oh, c’mon, you can do it with a Windows cmd file, too (this may wrap in the textarea) -

for %%v in (*.CR2) do echo Processing %%v & exiftool

-exif:OwnerName="Dave Pawson" -exif:Copyright="Dave Pawson 2008" %%v &

del %%v_original

\

Not that I’m agin *ix. I’ve been running a lot of them in virtual machines lately.\

Thanks Dave and Tom! (All note that Tom’s command should be written out as one line.)