ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: wes on December 15, 2022, 01:47:53 PM

Title: How to add Google Photo Sphere XMP data using Perl
Post by: wes on December 15, 2022, 01:47:53 PM
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.
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: StarGeek on December 15, 2022, 01:57:13 PM
Phil is currently away until next week, so your answer might have to wait until he gets back.
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: Phil Harvey on December 19, 2022, 10:31:36 AM
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
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: wes on December 20, 2022, 09:35:09 AM
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?
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: Phil Harvey on December 20, 2022, 12:51:36 PM
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
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: wes on December 20, 2022, 01:16:43 PM
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.
Title: Re: How to add Google Photo Sphere XMP data using Perl
Post by: Phil Harvey on December 20, 2022, 01:28:39 PM
The example you saw must have been a structure, but these are individual tags you are writing and not part of a structure.

- Phil