Assign Tag Value with Specific Type/Format/Bytes

Started by jeffreyke81, July 06, 2017, 12:40:09 AM

Previous topic - Next topic

jeffreyke81

Hi all,

First of all, thanks a lot for this awesome software!! It works perfectly in most cases, but I did bump into one problem and hope someone can shed some lights on it.

I am currently on an investigation to get our TIFF images validated by a validator. If I take a validated TIFF image and reassigned the IFD0:FileSource tag with ExifTool, it becomes invalid.
This problem is only observed on this particular FileSource tag (also tested with IFD0:DocumentName and image is still valid).

Here is the comment I ran
>> exiftool -IFD0:FileSource#=print [path to the image file]
If I use the command without #, I get an error with "not in PrintConv"
>> exiftool -IFD0:FileSource=print [path to the image file]

With further investigation and using -htmldump on the image "before" and "after" the FileSource assignment, I have noticed the only difference between two files is the tag value format - one is in string(6) and another is in undef(5). I have attached both htmldump files for your reference.

If my assumption is correct, the image would be valid if I can assign the right format to FileSource tag.
Is there any way I can force the FileSource field to be string(6) instead of undef(5)?

I have attached a few files in this thread as references.
0003-valid.html <-- the HTML dump for the valid TIFF image
0003-invalid.html <-- the HTML dump for the invalid TIFF image (After re-assigning the FileSource tag)
ValidImage.png <-- screenshot of the hexl view of the valid TIFF source
InvalidImage.png <-- screenshot of the hexl view of the invalid TIFF source
----
One last additional information, when I got the error from the validator, it gives a very "helpful" error message - "Type mismatch for tag 41728; expecting 2, saw 7 in...", where 2 and 7 should be super obvious to whoever looking at it, but except to me... :'(

Thank you in advance for any information you can provide.
Best regards,
Jeffrey

StarGeek

#1
Take a look at the listing for FileSource under Exif tags.  You'll see that there are only 4 values that FileSource can have, Film Scanner, Reflection Print Scanner, Digital Camera, and Sigma Digital Camera, though I bet the last isn't part of the EXIF specs.  The tag doesn't actually hold these values as a string, it holds a number which needs to be looked up to see what the value actually is, thus the PrintConv error.  Exiftool isn't able to convert the value according to the table for that tag.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

#2
QuoteIf I use the command without #, I get an error with "not in PrintConv"
>> exiftool -IFD0:FileSource=print [path to the image file]

Hi Jeffrey,

What version of exiftool are you using?  This is what you should get:

> exiftool -ver
10.58
> exiftool -IFD0:FileSource=print a.jpg
    1 image files updated
> exiftool -filesource -G1 a.jpg
[IFD0]          File Source                     : Reflection Print Scanner


But note that FileSource should be written to the ExifIFD, not IFD0.

> exiftool -validate -warning -a a.jpg
Validate                        : 1 Warning
Warning                         : Wrong IFD for 0xa300 FileSource (should be ExifIFD not IFD0)


This is how to write it to the correct location:

> exiftool -filesource=print a.jpg
    1 image files updated
> exiftool -validate -warning -a a.jpg
Validate                        : OK


ExifTool writes this tag correctly according to the EXIF specification.  If you want to write it incorrectly, you can always override the ExifTool definition of a tag with a user-defined tag.

- Phil

Edit: Added -validate examples.  (...thinking I may have opened a can of worms though.)
...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 ($).

StarGeek

Sorry, my mistake. I thought you were trying to put the whole path in the tag. I now see the space in your command.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

jeffreyke81

Thanks a lot StarGeek for the support!

Thank you Phil for the super fast reply. Didn't expect to receive the author's reply in such a short time! This is pretty awesome, thank you!

I have tried your suggestions, but I think the problem is the validator I am dealing with (from the Library of Congress, btw...) requires me to write out the FileSource tag incorrectly (not following the Exif spec)... Based on its error message, the FileSoure tag can only be microfilm, microfiche, print, 1, 2, or 3... So it doesn't look like it is expecting the values from the Exif spec.

I will have to try overwriting the tag definition using the -config option.

Quote from: Phil Harvey on July 06, 2017, 07:10:01 AM
QuoteIf I use the command without #, I get an error with "not in PrintConv"
>> exiftool -IFD0:FileSource=print [path to the image file]

Hi Jeffrey,

What version of exiftool are you using?  This is what you should get:

> exiftool -ver
10.58
> exiftool -IFD0:FileSource=print a.jpg
    1 image files updated
> exiftool -filesource -G1 a.jpg
[IFD0]          File Source                     : Reflection Print Scanner


I am using 10.58.

Quote from: Phil Harvey on July 06, 2017, 07:10:01 AM
But note that FileSource should be written to the ExifIFD, not IFD0.

> exiftool -validate -warning -a a.jpg
Validate                        : 1 Warning
Warning                         : Wrong IFD for 0xa300 FileSource (should be ExifIFD not IFD0)


This is how to write it to the correct location:

> exiftool -filesource=print a.jpg
    1 image files updated
> exiftool -validate -warning -a a.jpg
Validate                        : OK


I tried with "exiftool -filesource=print a.jpg", but the validator is still complaining...
If I ran "exiftool -validate -warning -a a.tif" on a valid image (by this validator I am dealing with), it shows warnings on both FileSource and ImageUniqueID for their group (should be in ExifIFD not IFD0)... I guess this tells me this validator is not following the Exif spec... :(

Quote from: Phil Harvey on July 06, 2017, 07:10:01 AM
ExifTool writes this tag correctly according to the EXIF specification.  If you want to write it incorrectly, you can always override the ExifTool definition of a tag with a user-defined tag.

Thanks a lot for the hint, I will try override the tag definition and see how it goes.
And no worries, these are my worms, let's see if we can turn them into fertilizers :D
Best regards,
Jeffrey

jeffreyke81

OMG~~ IT IS WORKING!!! [A Dancing Jeffrey]
My colleague sets next to me says I got way too much joy out of this thing.

Apparently, our assumption is correct... the validator, I am dealing with, is not following the Exif spec...
The solution is to override the tags so it assigns the value in a specific format.

%Image::ExifTool::UserDefined = (
  'Image::ExifTool::Exif::Main' => {
    0xa300 => {
      Name => 'FileSource',
      Writable => 'string',
      WriteGroup => 'IFD0',
    },

    0xa420 => {
      Name => 'ImageUniqueID',
      WriteGroup => 'IFD0',
    },
  },
);


Again, thanks a lot for the awesome software and great support.
Best regards,
Jeffrey

Phil Harvey

Hi Jeffrey,

Great!  Glad to hear you figured this out.

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