Ascertain the offset to thumbnail in EXIF

Started by Herman C, March 21, 2014, 03:34:17 PM

Previous topic - Next topic

Herman C

I believe ExifTool forum should be my last resort to resolve a problem I have in hand.  On an amateur/hobbyist basis I have been developing some graphic tools after my retirement.  In an on-going enhancement to my Paint program more recently, I have added a JPEG Mark Listing letting users to (i) carry out some operations on "marker" basis such as Add/Insert/Remove; and (ii) to inspect some information pertaining to a selected marker,  by a double-click on a selected marker, e.g. APP0 to see JFIF or JFXX header entries (and thumbnail if JFXX), SOF0 or SOF2 to see the respective header pieces,  and APP1 to view a listing of EXIF tags, with InterOp and GPS tags, if any, appended at the end in the listing. 

If there is a thumbnail in EXIF, the thumbnail image is also shown next to the above-said listing, with "Size", "Format", "Offset" and "Length" data.  Although I am able to get these, I am far from satisfied, because the thumbnail and the data are obtained through some kind of trick, not by an "official" means.  I obtain the thumbnail by testing "FFD8....FFD9" within EXIF bytes, then derive the said data in the course (I don't use any external DLL or EXE, not even GDIplus).

Earlier on I mentioned InterOp and GSP tags; they are obtained with the guidance of the respective offset values given in EXIF itself.  However, when it comes to thumbnail, I have failed to follow a similar path to obtain an "offset" for the thumbnail bytes.

Almost all of the web pages I visited had told me that there would be "JPEGOffset  513" and "JPEGLength  514" to refer to.  However, I have not been able to trap such tags in any of the many and assorted JPEG files that I have.  This forces me to just use the earlier-said trick to obtain the thumbnail and derive the offset and length data.

I wonder, is there a proper way of obtaining the "offset" of thumbnail bytes in EXIF?  If yes, how should I go about it?.  I should be grateful if someone is kind enough to enlighten me on this issue, thus satisfying my curiosity.


Phil Harvey

The EXIF information is in TIFF format.  The thumbnail image is stored in IFD1 of the TIFF information.  Reading the EXIF and TIFF specifications may help, but I find it REALLY helps to see how the data is arranged in the JPEG file.  For this, the ExifTool -htmlDump is priceless to me.  If you haven't discovered this feature, I suggest you investigate it.  If you have read the EXIF/TIFF specs, you should have an "ah-ha" moment after studying the -htmldump output.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Herman C

Hi Phil,

I thank you very much for your help. "ExifTool -htmlDump" is indeed a marvel.

Your "The thumbnail image is stored in IFD1....." immediately opened up my mind.  Then, by examining the output of "-htmlDump", to and fro a couple of times at a few byte positions, the "ah-ha" moment did come pretty soon.

Meanwhile, the "IFD data structure" section on the web page http://www.media.mit.edu/pia/Research/deepview/exif.html had spared me digging into the detailed TIFF/JPEG specifications.

My problem has now been resolved and I am grateful for your help.

Herman