Partial tag writing

Started by Joel, December 09, 2010, 08:47:16 PM

Previous topic - Next topic

Joel

I'm using XP and the files mentioned below are all jpg or jpeg.

I have 1000s of photos where I need to put their current file name in a tag and an ID number in another tag. This done, the photo file name changes.

The code thus far:

  my $success = $exifTool->SetNewValue(Keywords => $Keywords, AddValue => 0); #tell ExifTool which tag and what message
  $exifTool->WriteInfo($WithPath);                #put message in tag
  $success = $exifTool->SetNewValue(UserComment => $UserComment, AddValue => 0); #tell ExifTool which tag and what message
  $Result = $exifTool->WriteInfo($WithPath);                #put message in tag
$errStr = $exifTool->GetValue('Error');
die "$Result|$errStr";

The file name goes into Keywords just fine.

The ID goes into UserComment almost all the time.
Bad format (0) for IFD0 entry 0 for the rest.

My questions:

Can I get the reluctant files to accept the ID, or should I pick a different tag? If so, which?

Is there something else I should be doing? Perhaps a different approach?

One additional note: If I shrink the files with Easy Thumbnails, the shrunk files accept the old file name and the ID. There is something curative about Easy Thumbnails.

Phil Harvey

First of all, I hope you're not calling WriteInfo() twice for the same file.  The technique is to call SetNewValue() for each tag you want to write, then call WriteInfo() once for each different file you want to write all these tags to.

The "Bad format" error in IFD0 indicates a serious error that will prevent ExifTool from writing EXIF information to the file.  The EXIF in this file must be repaired before any new information may be written.  See FAQ number 20 for details.

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

Joel

Thank you so much for getting back to me so promptly.

> First of all, I hope you're not calling WriteInfo() twice for the same file.

I didn't know better. I'll mend my ways.

> The "Bad format" error in IFD0 indicates a serious error that will prevent ExifTool from writing EXIF information to the file.  The EXIF in this file must be repaired before any new information may be written.  See FAQ number 20 for details.

I put the following in my perl program per FAQ 20 :
exiftool -exif:all= -tagsfromfile @ -exif:all -unsafe -thumbnailimage -F AAAAACopy.jpg

I get a syntax error. I have no idea what it wants. I don't quite understand enough to get a toehold and proceed on my own.

Phil Harvey

#3
Right.  That was a command for the command line.  Use this to do it in your script:

$exifTool->SetNewValue('exif:*');
$exifTool->SetNewValuesFromFile($srcfile, 'exif:*', 'unsafe', 'thumbnailimage');
$exifTool->Options(FixBase => 1);
# [ set other tag values here with more calls to SetNewValue() ]
my $result = $exifTool->WriteInfo($srcfile, $dstfile);
my $error = $exifTool->GetValue('Error');
my $warning = $exifTool->GetValue('Warning');
# [...]


- Phil

Edit: But I should mention that you shouldn't be rebuilding the EXIF from scratch like this unless necessary because some information (such as a PreviewImage) may be lost.  So try it without this first, and only rebuild the EXIF if WriteInfo() fails.
...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 ($).

Joel

Your advice worked on the first try. Lots of pictures have been fixed. And perhaps more to come.

Thank you again for getting back to me so promptly, clearly, and accurately. I'm not use to that.