From b0fba1a831854b34ef3a80464ef8459c0fd405ce Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 24 Feb 2007 22:45:16 +0000 Subject: [PATCH] Allow RAW files. I can't believe that just worked. Closes #10. git-svn-id: http://svn.simon-cozens.org/memories/trunk@41 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 32 ++++++++++++++++++++++++-------- memories.sql | 3 ++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index b7696b1..a497600 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -2,7 +2,7 @@ package Memories::Photo; use File::Basename; use File::Copy; use Archive::Any; -use File::Temp qw(tempdir); +use File::Temp qw(tempdir tmpnam); use File::Path qw(rmtree); use File::Find; use File::MMagic; @@ -13,7 +13,7 @@ use constant INTERESTINGNESS_ALGORITHM => '((rating+3)/(rated+1))*(1+rated/hit_c use Time::Piece; use Image::Seek; use constant PAGER_SYNTAX => "LimitXY"; -__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count)); +__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count format)); __PACKAGE__->untaint_columns(printable => [qw/title/]); __PACKAGE__->columns(TEMP => qw/exif_object/); @@ -94,8 +94,10 @@ sub upload_file { my $mm = File::MMagic->new; my $res = $mm->checktype_filename($filename); warn "$filename is a $res\n"; - if ($res =~ m{/x-zip} or $offered_name =~ /t(ar\.)?gz/i) { + if ($res =~ m{/x-zip} or $offered_name =~ /t(ar\.)?gz$/i) { return $self->upload_archive($r, $filename); + } elsif ($offered_name =~ /\.(raw|nef)/i) { + return $self->upload_raw($r, $filename, $offered_name); } elsif ($res =~ m{image/jpeg}) { return $self->upload_jpeg($r, $filename, $offered_name); } else { @@ -118,6 +120,20 @@ sub upload_archive { return @results; } +sub upload_raw { + my ($self, $r, $filename, $offered_name) = @_; + my $jpg = tmpnam().".jpg"; + system("dcraw -c $filename | convert - $jpg"); + my $photo = $self->upload_jpeg($r, $jpg, $offered_name); + $filename =~ /\.(.*)$/; + my $format = $1; + $photo->format($format); + # Put the file in place + copy($filename, + Memories->config->{data_store}."/".$photo->id.".".$format); + return $photo; +} + sub upload_jpeg { my ($self, $r, $filename, $offered_name) = @_; my $photo = $self->create({ @@ -222,10 +238,6 @@ sub add_comment :Exported { }); } -sub format { - "jpg" # For now -} - use Cache::MemoryCache; use Image::Info qw(dim image_info); use Image::ExifTool; @@ -335,7 +347,11 @@ sub path { # Make dir if it doesn't exist, save trouble later use File::Path; if ($is_url ne "url") {mkpath($path);} - $path .= $self->id.".".$self->format; + if ($scale or $is_url ne "url") { + $path .= $self->id.".jpg"; + } else { + $path .= $self->id.".".($self->format||"jpg"); + } return $path; } diff --git a/memories.sql b/memories.sql index cf49797..898f288 100644 --- a/memories.sql +++ b/memories.sql @@ -7,7 +7,8 @@ CREATE TABLE photo ( y integer, hit_count integer, rating integer, - rated integer + rated integer, + format varchar(10) ); CREATE TABLE comment ( -- 2.39.5