[3e0be4]: bin / pto2gpano  Maximize  Restore  History

Download this file

113 lines (82 with data), 3.3 kB

use strict;
use warnings;
use 5.010;
use Panotools::Script;
use Image::ExifTool;
use Pod::Usage;

pod2usage (2) unless (scalar @ARGV);

for my $path_pto (@ARGV)
    say "Project file: $path_pto";

    my $path_jpg = $path_pto;
    $path_jpg =~ s/\.pto/.jpg/;
    next unless -e $path_jpg;

    my $pto = new Panotools::Script;
    $pto->Read ($path_pto) || next;

    my $format = undef;
    $format = 'cylindrical' if $pto->Panorama->{f} == 1;
    $format = 'equirectangular' if $pto->Panorama->{f} == 2;
    next unless $format;

    my $left = 0;
    my $top = 0;
    my $width = $pto->Panorama->{w};
    my $height = $pto->Panorama->{h};

    if (defined $pto->Panorama->{S})
        #  S100,600,100,800   Selection(left,right,top,bottom)
        my @crop = split ',', $pto->Panorama->{S};
        $left = $crop[0];
        $top = $crop[2];
        $width = $crop[1] - $crop[0];
        $height = $crop[3] - $crop[2];

    my $full_width = $pto->Panorama->{w};
    if ($pto->Panorama->{v} < 360)
        $full_width = int (360 * $full_width / $pto->Panorama->{v});
        $left += int (($full_width - $width) /2);

    my $path_first = $pto->Image->[0]->Path ($path_pto);
    my $path_last = $pto->Image->[-1]->Path ($path_pto);

    my $exiftool = new Image::ExifTool;
    $exiftool->SetNewValue ('UsePanoramaViewer', 'True');
    $exiftool->SetNewValue ('StitchingSoftware', 'Hugin');
    $exiftool->SetNewValue ('ProjectionType', $format);
    $exiftool->SetNewValue ('CroppedAreaLeftPixels', $left);
    $exiftool->SetNewValue ('CroppedAreaTopPixels', $top);
    $exiftool->SetNewValue ('CroppedAreaImageWidthPixels', $width);
    $exiftool->SetNewValue ('CroppedAreaImageHeightPixels', $height);
    $exiftool->SetNewValue ('FullPanoWidthPixels', $full_width);
    $exiftool->SetNewValue ('FullPanoHeightPixels', $pto->Panorama->{h});
    $exiftool->SetNewValue ('FirstPhotoDate', Image::ExifTool::ImageInfo ($path_first)->{DateTimeOriginal}) if -e $path_first;
    $exiftool->SetNewValue ('LastPhotoDate', Image::ExifTool::ImageInfo ($path_last)->{DateTimeOriginal}) if -e $path_last;
    $exiftool->SetNewValue ('SourcePhotosCount', scalar @{$pto->Image});

    $exiftool->WriteInfo ($path_jpg);
    say "JPEG file: $path_jpg";



=head1 NAME

pto2gpano - set XMP GPano metadata in a JPEG panorama


pto2gpano project1.pto project2.pto [...]

Options: None


Sets XMP metadata as described here, panoramas tagged with this metadata will
display in the Google+ panorama viewer:


This tool assumes that for each project.pto, there is an equivalent project.jpg
that needs updated metadata.  It also assumes that the original photos are
available to extract EXIF data info.

=head1 LICENSE

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

=head1 SEE ALSO


=head1 AUTHOR

Bruno Postle - January 2013.