Index: server/Slim/Utils/GDResizer.pm =================================================================== --- server/Slim/Utils/GDResizer.pm (revision 29777) +++ 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 @@ -166,6 +176,26 @@ $origImage = GD::Image->$constructor($file || $$origref); } + # 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; + }; + } + + if ( $hasEXIF && $in_format eq 'jpg' ) { + + my $orientation = Image::ExifTool::ImageInfo($file || $origref, 'Orientation#'); + + if ($orientation && (my $rotateMethod = $orientationToRotateMethod{$orientation->{Orientation}})) { + $origImage = $origImage->$rotateMethod(); + $debug && warn " Rotating image based on EXIF data using $rotateMethod()"; + } + } + my ($in_width, $in_height) = ($origImage->width, $origImage->height); # Output format