From: Jim N. <ji...@yo...> - 2009-04-03 21:00:00
|
I'm trying to write EXIF data back to the JPEG file it came from. This appears to be a problem for a number of people. If there's a general practice for this -- or available code! -- I'd love to know where to find it. My own experiments show that libexif is, for at least the photos I'm using, reducing the size of the EXIF data by approx. 1800 - 2000 bytes, even before my modifications. I assume this is due to padding in the original JPEG file that libexif bit-buckets at load time. Here's a general strategy I'm considering: 1. Read EXIF from the JPEG. Modify. 2. Flatten into buffer with exif_data_save_data(). 3. Examine JPEG file's APP1 segment. If APP1 length <= buffer length, write buffer directly into the APP1 segment in the file *without* modifying APP1's length field. Zero out remaining bytes in file. Done. 4. Otherwise, write out temporary file with SOI, APP1 with new EXIF and proper EXIF length, then copy remaining original file over. Move temporary file on top of original. Done. Step #3 is kind of dodgy ... will this work? I don't know enough about the EXIF or JPEG spec to understand if this is a problem (especially using zeroes as padding). I'm not worried about wasting 2000 bytes in a 1MB file. Thanks, -- Jim Nelson Yorba |