X-Git-Url: https://git.decadent.org.uk/gitweb/?p=memories.git;a=blobdiff_plain;f=Memories%2FPhoto.pm;fp=Memories%2FPhoto.pm;h=4e2a59dea02f719315ab98fee116b84bb80ff2cc;hp=69979892688ca19e77c7b71130c3042508ec391e;hb=5acf53e85633363aa8a207e9e08448f27a4544f9;hpb=293d891079d7545676d0a880b3b8c4f0ebacfd2c diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 6997989..4e2a59d 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -3,6 +3,7 @@ use strict; use Carp qw(cluck confess); 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__->untaint_columns(printable => [qw/title/]); @@ -48,6 +49,7 @@ sub do_upload :Exported { $photo->make_thumb; $photo->add_tags($r->{params}{tags}); + $photo->add_to_imageseek_library; Memories->zap_cache(); # Add system tags here @@ -64,6 +66,24 @@ sub do_upload :Exported { ); } +sub view :Exported { + my ($self, $r) = @_; + if ($r->{session}{last_search}) { + my $photo = $r->{objects}[0]; + # This is slightly inefficient + my @search = split/,/, $r->{session}{last_search}; + my $found = -1; + for my $i (0..$#search) { + next unless $photo->id == $search[$i]; + $found = $i; + } + return unless $found > -1; + $r->{template_args}{next} = $self->retrieve($search[$found+1]) + if $found+1 <= $#search; + $r->{template_args}{prev} = $self->retrieve($search[$found-1]) + if $found-1 >= 0; + } +} sub upload :Exported {} use Class::DBI::Plugin::Pager; @@ -80,6 +100,7 @@ sub recent :Exported { ); $r->objects([$pager->retrieve_all ]); $r->{template_args}{pager} = $pager; + $r->last_search; } sub add_comment :Exported { @@ -100,6 +121,35 @@ use Image::Info qw(dim image_info); use Image::ExifTool; my $cache = new Cache::MemoryCache( { 'namespace' => 'MemoriesInfo' }); +sub add_to_imageseek_library { + my $self = shift; + Image::Seek::cleardb(); + my $img = Image::Imlib2->load($self->path("file")); + + Image::Seek::add_image($img, $self->id); + # Merge this new one into the main database; there is a bit of a + # race condition here. XXX + Image::Seek::loaddb(Memories->config->{image_seek}); + Image::Seek::savedb(Memories->config->{image_seek}); +} + +sub recommended_tags { + my $self = shift; + my %tags = map { $_->name => $_ } + map { $_->tags } + $self->find_similar(3); + values %tags; +} + +sub find_similar { + my ($self, $count) = @_; + Image::Seek::cleardb(); + Image::Seek::loaddb(Memories->config->{image_seek}); + my @res = map {$_->[0] } Image::Seek::query_id($self->id, $count); + shift @res; # $self + map { $self->retrieve($_) } @res; +} + sub unrotate { my $self = shift; my $orient = $self->exif_info->{EXIF}->{Orientation};