How to add Google Photo Sphere XMP data using Perl

Started by wes, December 15, 2022, 01:47:53 PM

Previous topic - Next topic

wes

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.

StarGeek

Phil is currently away until next week, so your answer might have to wait until he gets back.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

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

wes

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?

Phil Harvey

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

wes

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.

Phil Harvey

The example you saw must have been a structure, but these are individual tags you are writing and not part of a structure.

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