ExifTool > The Image::ExifTool API

Deleting bad binary UserComment data

(1/1)

jwdevel:
I have a camera that sometimes produces binary junk in the UserComment EXIF tag (0x9286).

I have a program which processes images, and one of the things it does is (1) detect this junk and (2) remove it.

This was working in the past, but maybe I have a newer ExifTool or something else changed...

In my current state, I can detect the problem but the deletion is not working.
But maybe the way detection happens is having side-effects, so let me show that first:

I make this call early in my program:


--- Code: ---    AddUserDefinedTags(
            'Image::ExifTool::Exif::Main',
            0x9286 => {
                Name => 'UserComment',
                Format => 'undef',
                # No RawConv, which normally would be there, thwarting our
                # attempts to look at the real data.
                },
        ); 

--- End code ---

If I don't do this, then when I look at the 'UserComment' tag, I do *not* see the garbage binary data.
I forget where I learned this trick, so if it is not the right way, then please educate me.

I am reading the value with:


--- Code: ---    $et->GetValue('UserComment', 'Raw');

--- End code ---

And as I say, that part seems to work.

So, now I've detected it, and want to delete it.
So far, I had been using:


--- Code: ---    $et->SetNewValue('UserComment');
    ...
    $et->WriteInfo($filename);

--- End code ---

But the bad data is still there afterwards.

Some tidbits:

* This command does delete the tag fully:
--- Code: ---exiftool -UserComment= file.jpg
--- End code ---

If I run that with '-v4', I see in the output:


--- Code: ---    Deleting XMP-exif:UserComment
    Deleting ExifIFD:UserComment

--- End code ---

* However, when I run my own command with verbosity turned on, I only see:


--- Code: ---    Deleting XMP-exif:UserComment

--- End code ---

Perhaps this explains the discrepancy, but how do I accomplish the same in my code, rather than running exiftool?
I'm not sure what "-UserComment=" is really accomplishing, and it has been difficult deciphering that program ):

In case it is helpful, here is the (edited) output of "exiftool -v3 file.jpg", in one of the bad cases:


--- Code: ---  ExifByteOrder = II
  + [IFD0 directory with 13 entries]
  | 0)  ImageWidth = 4032
  |     - Tag 0x0100 (4 bytes, int32u[1]):
...
  | + [ExifIFD directory with 31 entries]
  | | 0)  ExposureTime = 0.05882352941 (1/17)
  | |     - Tag 0x829a (8 bytes, rational64u[1]):
...
  | |   Found IFD at offset 0x02dc in maker notes:
  | | + [MakerNotes directory with 7 entries]
  | | | 0)  MakerNoteVersion = 0100
  | | |     - Tag 0x0001 (4 bytes, undef[4]):
  | | |         02e6: 30 31 30 30                                     [0100]
...
  | | | 6)  FaceDetect = 0
  | | |     - Tag 0x0100 (2 bytes, int16u[1]):
  | | |         032e: 00 00                                           [..]
  | | 18) UserComment = ASCII.JKJK'..|.........~..|..|......".......V..m...;.......H...[snip]
  | |     - Tag 0x9286 (4980 bytes, undef[4980]):
  | |         033e: 41 53 43 49 49 00 00 00 0a 00 00 00 4a 4b 4a 4b [ASCII.......JKJK]
  | |         034e: 27 10 1b 7c f2 fd 00 00 9d 07 01 00 07 a9 01 00 ['..|............]
  | |         035e: f0 7e 01 00 01 00 00 00 00 7c ff ff 00 7c ff ff [.~.......|...|..]
  | |         036e: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [................]
  | |         037e: 00 00 00 00 80 00 85 00 c9 11 22 8a 01 00 00 00 [..........".....]
  | |         [snip 4900 bytes]

--- End code ---

At the end, you can see the garbage-filled UserComment tag.

StarGeek:
Just to let you know, Phil, the author of exiftool, is away until some time next week.  It'll probably be a bit of a wait to get an answer on this.

jwdevel:
Thanks for the heads up (:

jwdevel:
Well, after some experimentation today, I found that adding


--- Code: ---    Writable => 'undef',

--- End code ---

gets it working again.

I also added:


--- Code: ---    Binary => 1,

--- End code ---

since that seemed likely relevant, but I'm not 100% sure what that flag does.

I still would be interested in confirmation that this is all correct, though (:

Phil Harvey:
The "Binary => 1" definition just causes ExifTool to show the "Binary data XXX bytes" message instead of trying to print the data when extracting.

Yes.  Setting Writable to 'undef' will allow it to be written.  You don't need to set Format for reading since that is taken from the EXIF format type.

- Phil

Navigation

[0] Message Index

Go to full version