Batch processing of image files
For free, with ImageMagick.
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.
Comments
(Note: I usually close comments for an entry a few weeks after posting it to avoid comment spam.)
Hmm, this seems to fit the bill (PDF+image files)
http://www.sno.phy.queensu.ca/~phil/exiftool/
It's in Perl.
HTH
Posted by: perusio | March 3, 2008 9:51 AM
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.
Posted by: Bob DuCharme | March 3, 2008 10:10 AM
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.)
Posted by: John Cowan | March 3, 2008 10:40 AM
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.
Posted by: Bob DuCharme | March 3, 2008 11:38 AM
Posted by: Dave Pawson | March 3, 2008 11:47 AM
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
and then
would have done the same as you showed...
Albin
Posted by: Albin | March 3, 2008 12:49 PM
Oh, c'mon, you can do it with a Windows cmd file, too (this may wrap in the textarea) -
Not that I'm agin *ix. I've been running a lot of them in virtual machines lately.
Posted by: Tom Passin | March 3, 2008 11:32 PM
Thanks Dave and Tom! (All note that Tom's command should be written out as one line.)
Posted by: Bob DuCharme | March 4, 2008 10:25 AM