Exif and Perl

25 views
Skip to first unread message

Loren M. Lang

unread,
Sep 3, 2010, 8:30:48 AM9/3/10
to Life Logging
I've been working on figuring out how to properly use Image::ExifTool
and the best way to auto-rotate images. jpegtran from the libjpeg-progs
packages comes up as the only program to do a lossless image transform
and I can't find any direct perl interface for it. I could just use GD
to to a lossy transform when jpegtran isn't installed to keep it easier
to support Windows. Also, playing with jpegtran, I have confirmed that
it has no understanding of Exif data and normally it drops Exif data and
other extensions of JPEG by default. There is an option "-copy all"
with blindly copies Exif data but does not update it in anyway which
means an out-of-date thumbnail and an out-of-date orientation for
programs that use that information. I also found a program called
exifautotran in the libjpeg-progs packages. It uses the Exif
Orientation tag to figure out the correct transform and then calls
jpegtran with -copy all and it updates the orientation after jpegtran is
done. This is closer to what I want, but it does nothing more including
not updating the Exif Thumbnail. I was able to confirm this by dumping
all the exif data with exiftool and the thumbnail came out upside down.
After more searching, I found exiftran, "it's like jpegtran, but cares
about Exif data." Sounds promising, so I took a look. It's extremely
simple to use, exiftran -a -i *.jpg and your done. It updated both the
orientation tag and the thumbnail. I did a comparison with exiftool and
found out some interesting things. In addition to the Exif orientation
and thumbnails being updated, the ExifImageWidth and ExifImageHeight got
changed from 0x0 to 640x480. Those tags are distinctly different from
ImageWidth and ImageHeight tags. I read briefly through the Exif
specification for those tags, but I don't fully understand them.
Regardless, I don't think exiftran should have updated them. Also, the
GPS Time Stamp and GPS Image Direction tags got dropped oddly enough,
not sure why. exiftran also added a second JFIF header to the image. I
can now see JFIF occurring twice in my file. According to the Exif
spec, the JFIF is strictly incompatible, but according to the Wikipedia
article, many digital cameras add a JFIF header for compatibility with
non-Exif aware software, exiftran adds a second one which is most
certainly wrong and useless. For Exif-aware software, the JFIF header
just contains redundant information that has a chance of getting out of
date. I have a feeling the original JFIF header was left in with an out
of date thumbnail, but since it occurs after the new JFIF header, it
should be ignored. My last issue with exiftran is that it did not
update the Exif Modify Date like I was hoping. The final image shows
the Modify Date the same as the Date/Time Original and Create Date exif
tags. Maybe I should just use jpegtran with the -copy all option and
manually fix the Exif data afterwards. There also might be other
extended data besides Exif data worth saving, however, without a proper
understanding of it, it might just be left out of date.

--
Loren M. Lang
lor...@north-winds.org
http://www.north-winds.org/


Public Key: ftp://ftp.north-winds.org/pub/lorenl_pubkey.asc
Fingerprint: 10A0 7AE2 DAF5 4780 888A 3FA4 DCEE BB39 7654 DE5B

Loren M. Lang

unread,
Sep 3, 2010, 10:43:59 AM9/3/10
to lifel...@googlegroups.com
I wrote a quick JIF parser to better understand what was going on and
found out I was slightly mistaken. Whenever I saw the JFIF header after
the Exif header, it was one or more embedded JPEG thumbnails inside the
Exif header. Every image I have is either JFIF, Exif, or JFIF followed
by Exif for compatibility with non-Exif software. Exif-only is the most
common followed by a number of JFIF-only images created by my rather old
Nokia S40 phone. Second, none of my images actually contain the
optional embedded thumbnail supported by JFIF. If they have a
thumbnail, it's in the Exif data only. The tool exiftran was adding a
JFIF header to my Exif-only images to improve their compatibility with
non-Exif aware software. I don't think it's necessary, but seems to be
harmless.
Reply all
Reply to author
Forward
0 new messages