Reading iptc captions from jpegs with imagemagick

Rob and Spencer with zebras

Rob and Spencer with zebras

Once again I found myself needing to use imagemagick to do something, and was overwhelmed by the many options. After much fiddling around, I found out some options that worked for me.

In this case, I wanted to extract iptc captions from images, so that I could then insert the caption in a webpage with php. I use Picasa to edit photos and add captions. Picasa adds in the captions in the iptc information, which is the right place to add them. To extract the caption from the image above, do the following

convert robSpencer.jpg 8BIMTEXT:-

The result should be output to standard out:

2#120#Caption=”Rob and Spencer with zebras”

If you want to output to a file, simply do something like:

convert robSpencer.jpg 8BIMTEXT:filename.iptc

Now it easy to extract the caption using perl, python, php or whatever you like. For perl, we could simply pipe it:

convert robSpencer.jpg 8BIMTEXT:-|perl -ne '/Caption="(.*)"/; print $1;'

And in case you are interested, I needed to do this for the postie wordpress plugin which allows you to post to your blog via e-mail. In version 1.1.5 iptc captions will be read and displayed (if they are in the image you attach).

This entry was posted in linux, photography, wordpress and tagged , , , , . Bookmark the permalink.

One Response to Reading iptc captions from jpegs with imagemagick

  1. A licensed tax attorney can truly make a difference. Also, if you are audited by IRS, he can help you defend yourself for your best interest. I believe the tax deadline for 2011 is April 18th instead of April 15th so you have 3 more days to get yourself ready.