From: Dan F. <da...@co...> - 2009-04-04 01:29:54
|
On Fri, Apr 03, 2009 at 01:32:19PM -0700, Jim Nelson wrote: > 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. There used to be a little library called libjpeg that was a part of libexif, but it has since been moved to the exif command-line tool source package. You can easily copy that out and use it in your package, being mindful of the license, of course. > 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. That's likely. In some cases libexif will remove malformed tags that it runs into, which may be another reason for a size decrease. > 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. libjpeg should do what you need in this area. >>> Dan -- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved |