X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Memories%2FPhoto.pm;h=4279dc97c0eb4c622ec365390d97dd424938ae3e;hb=0ac6758a593e0e8ebad7af6aba3c3512d4d8280f;hp=4e2a59dea02f719315ab98fee116b84bb80ff2cc;hpb=b9d021d4af1018ac2c60640678c1b790251190e9;p=memories.git diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 4e2a59d..4279dc9 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -5,7 +5,7 @@ use base qw(Memories::DBI Maypole::Model::CDBI::Plain); use Time::Piece; use Image::Seek; use constant PAGER_SYNTAX => "LimitXY"; -__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y)); +__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count)); __PACKAGE__->untaint_columns(printable => [qw/title/]); __PACKAGE__->columns(TEMP => qw/exif_object/); __PACKAGE__->set_sql(recent => q{ @@ -30,7 +30,10 @@ 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}, + hit_count => 0, + rating => 0, + rated => 0, # Oh, the potential for divide by zero errors... }); # Dump content @@ -45,7 +48,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}); @@ -68,8 +74,9 @@ sub do_upload :Exported { sub view :Exported { my ($self, $r) = @_; + my $photo = $r->{objects}[0]; + $photo->hit_count($photo->hit_count()+1); if ($r->{session}{last_search}) { - my $photo = $r->{objects}[0]; # This is slightly inefficient my @search = split/,/, $r->{session}{last_search}; my $found = -1; @@ -174,16 +181,20 @@ sub exif_info { $info; } +my %banned_tags = map { $_ => 1 } + qw( CodedCharacterSet ApplicationRecordVersion ); + sub _exif_info { my $exifTool = new Image::ExifTool; - $exifTool->Options(Group0 => ['EXIF', 'MakerNotes', 'Composite']); + $exifTool->Options(Group0 => ['IPTC', 'EXIF', 'XMP', 'MakerNotes', 'Composite']); my $info = $exifTool->ImageInfo(shift->path); my $hash = {}; foreach my $tag ($exifTool->GetFoundTags('Group0')) { + next if $banned_tags{$tag}; my $group = $exifTool->GetGroup($tag); my $val = $info->{$tag}; next if ref $val eq 'SCALAR'; - next if $val =~ /^[0\s]*$/; + next if $val =~ /^[0\s]*$/ or $val =~ /^nil$/; $hash->{$group}->{$exifTool->GetDescription($tag)} = $val; } return $hash; @@ -276,15 +287,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;