At the Hadrian Hotel

At the Hadrian Hotel

Monday, May 21, 2007

Don't use Preview on the Mac to write EXIF keywords

If you read this blog, you may have realized by now that I'm a fan of flickr. As I write this, I have 791 photos uploaded to flickr. One of the things I like about flickr is the ability to tag photos, and one of the features of the flickr uploadr (buy a vowel already :-) ) for the Mac is that it will use EXIF (IPTC, really) keywords as tags for uploaded photos.

I've been using Phil Harvey's excellent exiftool to do all sorts of header manipulations as well as jhead to reset the filesystem timestamp once I'm all done mucking around with the file. Not too long ago, I discovered that the Preview application on the Mac will let you set keywords as well. Even though I am a command line kind of guy, I liked the idea of setting keywords for an image while I was actually looking at it. So I went through and added keywords to about 50 pictures. I then went to reset the date using jhead, and it complained about the EXIF header directory. I used exiftool to take a look, and it told me there was a problem with the IDF0 directory. Hmmm....

I contacted Phil to ask him if he could enlighten me at all on the problem. He was kind enought to respond almost immediately with an explanation of the error, a way I could find it myself (use 'exiftool -htmldump0') and even a way to fix it! Talk about customer service. Thanks, Phil!

It turns out that in the process of writing the keywords to the .JPG file, Preview would delete the YCbCrPositioning tag from IFD0 but not update the entry count for the IFD. That would corrupt the structure for pretty much everything following the now missing entry. This turns out to be a fair amount of stuff.

Phil suggested that I open a case with Apple, so I gave them a call. After spending about 10 minutes trying to explain what an EXIF header was, why it was important, and what Preview was doing to damage it, the woman at Apple put me on hold. When she came back, she said that they did some testing and since there didn't seem to be a subsequent problem with iPhoto and iDVD, there was nothing she could do for me. Grrrr....

I spent a few more minutes trying to explain why having an Apple application corrupt their users' data was a bad thing. She finally gave in and transferred me to an application specialist. I had to spend some time with him explaining the whole problem again, including the bit about my disappointment with the original "it works for us" response I received. I then remembered that Aperture was an Apple product that might actually care about the contents of the EXIF header and mentioned this to him. I was told to call back in a few days to see if he was able to find out anything useful for me.

I called back today and spoke to the specialist. He said that he had discussed the problem with the product engineers and that they knew about it. They told him that there are no plans to fix the problem at this time and the work-around is to not use Preview to set keywords in photos. As you might imagine, this was not exactly the response I was hoping for. However, in light of the initial response I got when reporting the problem, I probably should have expected it. Sigh....

If you want to try this at home, here's what to do. First, make a copy of the photo you want to work on. Open the copy in Preview and type <APPLE>-I (type 'i' while holding down the "Apple" key). A window will pop up with 3 tabs, the third of which is "Keywords." Click on that tab and then the "Add" button in the bottom of the window. Do this as many times as you want and then exit Preview. You will be prompted to save you changes, which you should do.

Now, open up a Terminal window and 'cd' to the directory where the photo files reside. Run 'exiftool -htmldump0' against the original photo and redirect the output to something ending in ".html." Do the same thing with the modified photo, using a different filename for the output, of course. Back in the GUI, double-click on the 2 ".html" files and compare the output. Scan down the right side of the pages looking for "IDF0-" entries. You should see "invalid IFD entry" listed for the modified photo. If you look at the page for the non-modified photo, you should see a whole bunch of information about your photo that is now lost in the modified image. It is possible to update the "IFD0 entries" field to get back most of the missing information, but it is not for those uncomfortable with the command line....

5 comments:

Anonymous said...

Can you confirm that preview is still writting bad exif ?

http://www.cpanforum.com/threads/5192

Chris Tengi said...

As Phil mentioned in the cpanforum thread, Apple has no plans to fix this problem at this time. That is what they told me on the phone. My Apple case number was 78500700, in case that is of any use to anybody.

So, yes, I can confirm that Preview is still writing bad EXIF headers (if/when I add keywords), because there has been no update to the program.

Jon said...

Really? I tried it with OSX 10.4.9 but I can't get it to corrupt files?

I have lots of problems with Aperture and its corrupt jpgs though.. :( Filed a bug report to Apple.

Jon said...

Ah I got it to corrupt a file! The "problem" was the picture I was testing with contained GPS tags - and I've seen that when a single GPS tag is present the file won't get messed up!!

I saw the same thing with Aperture.

Joshua said...

just a quick note:

Could someone test putting in a blank, or otherwise inconsequential GPS tag on a photo and see if it still corrupts?

Possibly it goes through different logic?