Index: server/Slim/Utils/GDResizer.pm =================================================================== --- server/Slim/Utils/GDResizer.pm (revision 29890) +++ server/Slim/Utils/GDResizer.pm (working copy) @@ -18,7 +18,17 @@ 'png' => 'newFromPng', ); +# rotation methods matching the EXIF Orientation flag +my %orientationToRotateMethod = ( +# 2 => 'copyFlipHorizontal', + 3 => 'copyRotate180', +# 4 => 'copyFlipVertical', + 6 => 'copyRotate90', + 8 => 'copyRotate270', +); + my $debug; +my $hasEXIF; # XXX: see if we can remove all modes besides pad/max @@ -119,6 +129,21 @@ $mode = 'm'; } + # optionally load Image::ExifTool to automatically rotate images if possible + # load late as it might be provided by some plugin instead of the system + if ( !defined $hasEXIF ) { + $hasEXIF = 0; + eval { + require Image::ExifTool; + $hasEXIF = 1; + }; + } + + my $orientation; + if ( $hasEXIF && $in_format eq 'jpg' ) { + $orientation = Image::ExifTool::ImageInfo($file || $origref, 'Orientation#', { FastScan => 2 }); + } + # Bug 6458, filter JPEGs on win32 through Imager to handle any corrupt files # XXX: Remove this when we get a newer build of GD if ( ISWINDOWS && $in_format eq 'jpg' ) { @@ -166,6 +191,12 @@ $origImage = GD::Image->$constructor($file || $$origref); } + # rotate image if original image had rotation information stored in the EXIF data + if ( $orientation && $orientation->{Orientation} && (my $rotateMethod = $orientationToRotateMethod{$orientation->{Orientation}}) ) { + $origImage = $origImage->$rotateMethod(); + $debug && warn " Rotating image based on EXIF data using $rotateMethod()\n"; + } + my ($in_width, $in_height) = ($origImage->width, $origImage->height); # Output format