I am trying to use the Perl Image::ExifTool module to add Google Photo Sphere data to an image. I am having trouble figuring out the correct syntax. Can someone help me with this code?
my $exifTool = Image::ExifTool->new;
$exifTool->SetNewValue('XMP-GPano:FullPanoWidthPixels', 14000);
my $success = $exifTool->WriteInfo($infile, $outfile);
I've tried many permutations of the first argument to "SetNewValue". No matter what I try, the tag is not added to the output file. I'm guessing that the syntax of that argument is my problem but I don't really know.
Phil is currently away until next week, so your answer might have to wait until he gets back.
Your code works fine for me provided that $infile exists and $outfile doesn't. Check to see that $success returns 1.
Maybe try adding this after creating the ExifTool object to get more details:
$exifTool->Options(Verbose => 2);
- Phil
Thanks Phil! The problem was that the output file already existed. I was trying over and over thinking it would overwrite the file each time.
Now that the following line works:
$exifTool->SetNewValue('XMP-GPano:FullPanoWidthPixels', 14000);
I am trying to get this to work:
$exifTool->SetNewValue('XMP-GPano' => {
UsePanoramaViewer => 'True',
ProjectionType => 'equirectangular',
StitchingSoftware => 'ICE',
CroppedAreaImageWidthPixels => 14000,
CroppedAreaImageHeightPixels => 7000,
FullPanoWidthPixels => 14000,
FullPanoHeightPixels => 7000,
CroppedAreaLeftPixels => 0,
CroppedAreaTopPixels => 0
});
However, this error is generated.
Tag 'XMP-GPano' is not defined or has a bad language code
What am I doing wrong?
Try this:
my %tags = (
'XMP-GPano:UsePanoramaViewer' => 'True',
'XMP-GPano:ProjectionType' => 'equirectangular',
'XMP-GPano:StitchingSoftware' => 'ICE',
'XMP-GPano:CroppedAreaImageWidthPixels' => 14000,
'XMP-GPano:CroppedAreaImageHeightPixels' => 7000,
'XMP-GPano:FullPanoWidthPixels' => 14000,
'XMP-GPano:FullPanoHeightPixels' => 7000,
'XMP-GPano:CroppedAreaLeftPixels' => 0,
'XMP-GPano:CroppedAreaTopPixels' => 0,
);
$exifTool->SetNewValue($_, $tags{$_}) foreach keys %tags;
or this if you want to use your existing hash:
my %tags = (
UsePanoramaViewer => 'True',
ProjectionType => 'equirectangular',
StitchingSoftware => 'ICE',
CroppedAreaImageWidthPixels => 14000,
CroppedAreaImageHeightPixels => 7000,
FullPanoWidthPixels => 14000,
FullPanoHeightPixels => 7000,
CroppedAreaLeftPixels => 0,
CroppedAreaTopPixels => 0,
);
$exifTool->SetNewValue("XMP-GPano:$_", $tags{$_}) foreach keys %tags;
- Phil
Thank you. The method you suggested works. I saw an example similar to what I was trying thinking that would be a way to accomplish the same thing using one call.
The example you saw must have been a structure, but these are individual tags you are writing and not part of a structure.
- Phil