|
Hi Mark,
It is clear you are struggling a bit with Perl. You have inserted a '$' symbol
and removed the required "Image::" in the tag table names. Also the '%'
isn't used when giving the table name in the value for TagTable.
As well, you need brackets around your list of variables after "my", and
the "\n" needs to be in double quotes because it is taken literally
in single quotes. So try this:
#!/usr/bin/perl
use warnings;
# ============================== Load modules ====================================
#use DBI;
use Image::ExifTool qw(:Public);
my ($picFile, $picFileMod);
$picFile = 'a.jpg';
$picFileMod = 'b.jpg';
#define ExifTool object;
my $ExifTool = new Image::ExifTool;
%Image::ExifTool::UserDefined::defra = (
GROUPS => { 0 => 'XMP', 1 => 'XMP-defra', 2 => 'Image' },
NAMESPACE => { 'defra' => 'http://ns.defra.com/' },
WRITABLE => 'string',
Tag1 => {},
Tag2 => {},
Tag3 => {}
);
%Image::ExifTool::UserDefined = (
# new XMP namespaces (ie. XMP-xxx) must be added to the Main XMP table:
'Image::ExifTool::XMP::Main' => {
defra => {
SubDirectory => {
TagTable => 'Image::ExifTool::UserDefined::defra'
},
},
}
);
if(-e $picFile)
{
my $info = $ExifTool->ImageInfo($picFile);
print "\n\n";
foreach (keys %$info) {
print "$_ => $$info{$_}\n";
}
$ExifTool->SetNewValue('Tag1','Val1');
$ExifTool->SetNewValue('Tag2','Val2');
$ExifTool->SetNewValue('Tag3','Val3');
$ExifTool->WriteInfo($picFile, $picFileMod);
}
print "After mod=============================================== \n";
my $info = ImageInfo($picFileMod);
foreach (keys %$info) {
print "$_ => $$info{$_}\n";
}
#end
Also, you will save yourself a lot of headaches in the future if
you check the return value from WriteInfo() and Error and Warning
messages to see if there were any problems when writing
the file. The the API documentation on WriteInfo for details.
- Phil
|