WriteInfo - Am I doing something wrong??

Started by ladoota, March 03, 2011, 04:24:00 AM

Previous topic - Next topic

ladoota

Hi,
I am trying to to a very basic thing: read IPTC Caption-Abstract an then write it into the corresponding EXIF and XMP tags. Perl is Activestate v5.10.1, EXIFTool is 8.40. WriteInfo simply doesnot work. I doublechecked folder permissions - they are OK. I checked the jpg files - I can work with them in PS and edit meta info OK. I don't know what else should I check. Sample code is below - if there is an error in it I cannot find it for the life of me... Does some one has any suggetion what should I try?

#!/usr/bin/perl -w
use strict;
use Image::ExifTool;

my $infile  = shift;
my $outfile = "D:/test/test.jpg";

my $exifTool = new Image::ExifTool;
my $info     = $exifTool->ImageInfo($infile);

my $caption  = $$info{"Caption-Abstract"} . "\n";
$exifTool->SetNewValue( ImageDescription => $caption );
$exifTool->SetNewValue( Description      => $caption );
$result = $exifTool->WriteInfo( $infile, $outfile );

if ($result != 0){
   print "$outfile, modified OK ...\n";
}


Phil Harvey

Your script is fine (aside from the fact that you need to define $result), and should work provided that

a) The input file exists

b) The input file contains an IPTC:Caption-Abstract tag

c) The output file does not exist

d) The output directory exists

You should add some checks in the code to make sure $$info{"Caption-Abstract"} exists.  If not, check $$info{Error} to see if there was an error.  If the write doesn't work, call $exifTool->GetValue('Error') to see what the error was.

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

ladoota

Thanks for quick reply. The undefined $result was due to quick (and little bit careless) cut/paste I've done in order to eliminate 'noise' from the needed sample.

I followed your advice and it turned out that I was trying to deal with some defective jpeg files after all. Photoshop (cs3) is perfectly happy with them but when I tried the $exifTool->GetValue('Error') it had some issue trying to write EXIF info to a file. I was later able to see the same error while using the command line version of EXIFTool.

So far it seems that this difficulty is limited to jpegs produced by a Nikon D90 that we have. I am not yet sure if this is the case with this particular (possibly defective ?) D90 camera or if that's more common problem. I'll investigate a little more tomorrow.

But anyway my immediate problem is solved for time being.

Regards, Vladimir

Phil Harvey

Hi Vladimir,

If all the errors are "[minor]", you can set $exifTool->Options(IgnoreMinorErrors => 1); before WriteInfo() to allow the file to be written.

It is likely the error was caused by editing the image with some other software.  JPEG's straight out of a D90 shouldn't cause this problem (unless Nikon introduced a bug I haven't seen yet in a firmware update).

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