diff --git a/fotostore.pl b/fotostore.pl index a125e81..220946a 100644 --- a/fotostore.pl +++ b/fotostore.pl @@ -166,15 +166,36 @@ post '/upload' => (authenticated => 1)=> sub { my $imager = Imager->new(); $imager->read(file => $image_file) or die $imager->errstr; + + #http://sylvana.net/jpegcrop/exif_orientation.html + my $rotation_angle = $imager->tags( name => "exif_orientation"); + $self->app->log->info("Rotation angle [".$rotation_angle."]"); for my $scale (@scale_width) { + if ($rotation_angle == 3) { + $imager = $imager->rotate(degrees=>180); + } + elsif ($rotation_angle == 6) { + $imager = $imager->rotate(degrees=>90); + } + my $scaled = $imager->scale(xpixels => $scale); + $scaled->write(file => File::Spec->catfile($IMAGE_DIR, $scale, $filename)) or die $scaled->errstr; } + $self->render(json => {files => [ + { + name => $filename, + size => $image->size, + url => sprintf('/images/orig/%s', $filename), + thumbnailUrl => sprintf('/images/200/%s', $filename), + }] + }); + # Redirect to top page - $self->redirect_to('index'); + # $self->redirect_to('index'); } => 'upload'; @@ -235,19 +256,44 @@ __DATA__