w0, h0 width and height of original image
title photo title
fmt photo format (png/jpg; defaults to jpg)
+ lat geographic latitude in degrees north of equator
+ lon geographic longitude in degrees east of Greenwich
+ alt geographic altitude in meters
+ t time when the photo was taken (2014-01-25 09:40:12)
The rest is present in cache.meta only:
# Simple Photo Gallery
-# (c) 2003--2012 Martin Mares <mj@ucw.cz>
+# (c) 2003--2014 Martin Mares <mj@ucw.cz>
package UCW::Gallery;
PhotoMaxHeight => 1024,
ThumbFormats => [ "114x94" ], # Built-in themes use the first size,
# but more can be generated
+ CacheExif => 0, # Cache selected EXIF meta-data
# Titles and navigation
Title => 'An Unnamed Gallery',
use warnings;
use UCW::Gallery;
+use Image::EXIF;
use Image::Magick;
use IO::Handle;
use File::Spec;
$m->{h} = $h;
}
+sub get_meta_exif($$) {
+ my ($f, $m) = @_;
+ $gal->get('CacheExif') or return;
+
+ my $e = new Image::EXIF($f->{orig});
+ my $i = $e->get_all_info();
+ if ($e->error) {
+ print "[EXIF error: ", $e->error, "] ";
+ return;
+ }
+ # use Data::Dumper; print Dumper($i);
+
+ my $lat = $i->{image}->{'Latitude'};
+ if ($lat) {
+ if ($lat =~ m{^([NS]) (\d+)\xb0 ([0-9.]+)'$}) {
+ $lat = $2 + $3/60;
+ $lat = -$lat if $1 eq 'S';
+ $lat = sprintf "%.6f", $lat;
+ } else {
+ print "[EXIF: unable to parse latitude $lat] ";
+ $lat = undef;
+ }
+ }
+
+ my $lon = $i->{image}->{'Longitude'};
+ if ($lon) {
+ if ($lon =~ m{^([WE]) (\d+)\xb0 ([0-9.]+)'$}) {
+ $lon = $2 + $3/60;
+ $lon = -$lon if $1 eq 'W';
+ $lon = sprintf "%.6f", $lon;
+ } else {
+ print "[EXIF: unable to parse longitude $lon] ";
+ $lon = undef;
+ }
+ }
+
+ my $alt = $i->{image}->{'Altitude'};
+ if ($alt) {
+ if ($alt =~ m{^([0-9.]+) m$}) {
+ $alt = $1;
+ } else {
+ print "[EXIF: unable to parse altitude $alt] ";
+ $alt = undef;
+ }
+ }
+
+ # printf "[GEO: lat=%s lon=%s alt=%s] ", $lat // '?', $lon // '?', $alt // '?';
+ if ($lat && $lon) {
+ $m->{lat} = $lat;
+ $m->{lon} = $lon;
+ }
+ $m->{alt} = $alt if $alt;
+
+ my $time = $i->{image}->{'Image Created'};
+ if ($time) {
+ if ($time =~ m{^(\d{4}):(\d{2}):(\d{2}) (\d{2}:\d{2}:\d{2})$}) {
+ $m->{t} = "$1-$2-$3 $4";
+ # print "[TIME: ", $m->{t}, "] ";
+ } else {
+ print "[EXIF: unable to parse time $time] ";
+ }
+ }
+}
+
sub generate_photo($$$) {
my ($f, $m, $p) = @_;
my $p = new Image::Magick;
get_meta_basic($f, $m, $p);
+ get_meta_exif($f, $m);
my $om = $old_meta->{photo}->{$id};
if ($om &&