From af01b9b60fb8342adaca76f30bc9f9209d6bc326 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 6 Feb 2007 22:11:05 +0000 Subject: [PATCH] Start to do some more with the metadata. References #1, #2. git-svn-id: http://svn.simon-cozens.org/memories/trunk@6 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 67e9d5f..960810d 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -30,7 +30,7 @@ sub do_upload :Exported { my $photo = $self->create({ uploader => $r->user, uploaded => Time::Piece->new(), - title => ($r->params->{title} || $upload{filename}) + title => $r->params->{title} }); # Dump content @@ -45,7 +45,10 @@ sub do_upload :Exported { $photo->x($x); $photo->y($y); # Rotate? - $photo->unrotate(); + $photo->unrotate(); + if (!$photo->title){ + $photo->title($photo->title_exif || $upload{filename}); + } $photo->make_thumb; $photo->add_tags($r->{params}{tags}); @@ -280,15 +283,35 @@ sub add_tags { } } +# Work out some common properties from a set of potential photo metadata +# tags +sub _grovel_metadata { + my ($self, @tags) = @_; + my %md = map {%$_} values %{$self->exif_info}; + for (@tags) { + if ($md{$_} and $md{$_} =~/[^ 0:]/) { return $md{$_} } + } + return; +} + sub shot { - my $self = shift; - my $exif = $self->exif_info->{EXIF}; - my ($dt) = - grep {$_ and /[^ 0:]/} - ($exif->{ 'Shooting Date/Time' }, - $exif->{ 'Date/Time Of Digitization' }, - $exif->{ 'Date/Time Of Last Modification' }); - if (!$dt) { return $self->uploaded } - return Time::Piece->strptime($dt, "%Y:%m:%d %T") || $self->uploaded; + my $self = shift; + my $dt = $self->_grovel_metadata( + 'Shooting Date/Time', + 'Date/Time Of Digitization', + 'Date/Time Of Last Modification' + ); + if (!$dt) { return $self->uploaded } + return Time::Piece->strptime($dt, "%Y:%m:%d %T") || $self->uploaded; } + +sub description { + shift->_grovel_metadata( + 'Description', 'Image Description', 'Caption-Abstract' + ); +} + +sub title_exif { shift->_grovel_metadata( 'Headline', 'Title'); } +sub license { shift->_grovel_metadata( 'Rights Usage Terms', 'Usage Terms' ) } +sub copyright { shift->_grovel_metadata( 'Rights', 'Copyright', 'Copyright Notice') } 1; -- 2.39.5