Please help check I'm writing EXIF and IPTC tags properly

Started by joakimk, March 23, 2017, 03:45:02 PM

Previous topic - Next topic

Phil Harvey

Quote from: joakimk on March 28, 2017, 04:02:26 PM
It always ends up in the wrong IFD (IFD0, instead of... IFD1?):

Warning                         : Wrong IFD for ExifIFD tag 0x010e ImageDescription (found in IFD0)

As I said, the warning needs to be fixed.  It should read "should be in IFD0".  It is currently in ExifIFD.  I will fix this message in the next release.

The "Odd offset" problems are common, which is why they are indicated as "[minor]".  You are safe to ignore these.

- 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 ($).

joakimk

Yes, the error says the ImageDescription field should be in IFD0, and not ExifIFD. As I learn more about EXIF, I understand more on how to use the Apache library. For the Exif tags, I get and write to the ExifDirectory, and that seems to work. But I need to write ImageDescription to a different directory, right?

I find the following directories in the JPEGs:

loadUI() on file /storage/emulated/0/Download/indonesia_monkey_wpo-5.jpg; inspecting metadata:
Found directory #0: Root
Found directory #1: Exif
Found directory #2: Gps
Found directory #3: Sub


Am I correct to assume Root is IFD0? Trying that, I no longer get the "Wrong IFD" error from ExifTool. Would you mind checking if the attached image looks correct? I have tried to check for myself, but -htmldump seems to reveal that the ExifIFD part now comes "before" (above) IFD0. But maybe that's not a problem/error? My app lists the directories in the same order as above, even after editing.


Phil Harvey

Most EXIF tags are in the ExifIFD, but some (the ones defined by the TIFF specification) are in IFD0.  The EXIF spec tells you which one it should go in.

- 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 ($).

joakimk

Hello again :)

I've been in touch with the people maintaining and developing the Apache library for editing image data and meta data (Apache Commons Imaging, previously Apache Sanselan), and they have found a patch for the bug which introduced the odd offsets when writing EXIF data.

Using this patched version of Sanselan (while waiting for the first stable release of Imaging), I've tested on a Nexus LG 5. As I said earlier (above), the original image (as produced by the camera on the device) does not validate with ExifTool:


$ ./exiftool\(-k\).exe -validate -warning -error -a ../IMG_20171223_200655.jpg
-- press RETURN --

Validate                        : 32 Warnings (6 minor)
Warning                         : Entries in IFD0 are out of order
Warning                         : Tag ID 0x0110 out of sequence in IFD0
Warning                         : Tag ID 0x0100 out of sequence in IFD0
Warning                         : Tag ID 0x0128 out of sequence in IFD0
Warning                         : Tag ID 0x0101 out of sequence in IFD0
Warning                         : Tag ID 0x0112 out of sequence in IFD0
Warning                         : Entries in ExifIFD are out of order
Warning                         : Tag ID 0x9004 out of sequence in ExifIFD
Warning                         : Tag ID 0x829d out of sequence in ExifIFD
Warning                         : Tag ID 0x9202 out of sequence in ExifIFD
Warning                         : Tag ID 0xa002 out of sequence in ExifIFD
Warning                         : Tag ID 0x9290 out of sequence in ExifIFD
Warning                         : [minor] Odd offset for ExifIFD tag 0x9201
Warning                         : Tag ID 0x9201 out of sequence in ExifIFD
Warning                         : [minor] Odd offset for ExifIFD tag 0x9003
Warning                         : Tag ID 0x9003 out of sequence in ExifIFD
Warning                         : [minor] Odd offset for ExifIFD tag 0x9292
Warning                         : Tag ID 0x9101 out of sequence in ExifIFD
Warning                         : Tag ID 0x9209 out of sequence in ExifIFD
Warning                         : Tag ID 0x9000 out of sequence in ExifIFD
Warning                         : Tag ID 0x8827 out of sequence in ExifIFD
Warning                         : Tag ID 0x9291 out of sequence in ExifIFD
Warning                         : [minor] Odd offset for ExifIFD tag 0x829a
Warning                         : Tag ID 0x829a out of sequence in ExifIFD
Warning                         : Tag ID 0x011a out of sequence in IFD0
Warning                         : Tag ID 0x010f out of sequence in IFD0
Warning                         : [minor] Odd offset for IFD1 tag 0x011b
Warning                         : Entries in IFD1 are out of order
Warning                         : Tag ID 0x0201 out of sequence in IFD1
Warning                         : Tag ID 0x0103 out of sequence in IFD1
Warning                         : [minor] Odd offset for IFD1 tag 0x011a
Warning                         : Tag ID 0x011a out of sequence in IFD1


However, if I edit the file using my app (with the patched library) then the JPEG does validate:


$ ./exiftool\(-k\).exe -validate -warning -error -a ../IMG_20171223_200655_2.jpg
-- press RETURN --

Validate                        : OK


So, it seems the patch/fix (which, while writing tags, checks if offsets are even or odd, and adds 1 and rounds up to an even byte length if odd) "repairs" the offsets, such that the file validates. Could you please have a look at the two files in question -- once again -- and see if you agree (that the second file looks better than the original one)?

The tags I've updated (added) are, EXIF UserComment, EXIF ImageDescription, and IPTC Caption/Abstract. And I think I've got the details right (according to the EXIF standard):





EXIFUserCommentUTF16 (big endian)FIELD_TYPE_UNDEFINEDPrepend string to write with ASCII bytes spelling out "UNICODE": byte[] ASCIIMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44, 0x45, 0x00 };
EXIFImageDescriptionUS-ASCIIFIELD_TYPE_ASCIIAlways null-terminate string (with 0x00) regardless of odd/even length
IPTCCaption/Abstract(uses a different part of the Sanselan library -- the Photoshop part -- which I am less familiar with than the EXIF parts)


P.s. I'll email the files; the attach/upload function does not work.

Phil Harvey

Yes, ExifTool will fix the odd offsets and out-of-order tags.  These requirements are part of the TIFF6 specification, upon which EXIF is based.

- 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 ($).

joakimk

But this file (the _2 version) has been edited by Apache Sanselan, not by ExifTool. I know ExifTool will handle standards and repair structure, but I guess I'm asking if you might verify that the patched version of Sanselan also has it's bytes in order? At least in this particular example (I emailed you the files I couldn't attach).

Phil Harvey

I see.  Yes, the edited file looks fine.  (No red in the htmlDump output means no odd offsets and no tag ordering problems)

- 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 ($).