Don't re-apply EXIF rotation to chained thumbnails
authorGilles Dubuc <gdubuc@wikimedia.org>
Thu, 13 Nov 2014 10:26:15 +0000 (11:26 +0100)
committerGilles Dubuc <gdubuc@wikimedia.org>
Thu, 13 Nov 2014 10:26:15 +0000 (11:26 +0100)
Change-Id: I2f0674e4aea508ad7e00b7742a9d47bd0659e399
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/600
Bug: 67525
Bug: 73352

includes/media/Bitmap.php
includes/media/TransformationalImageHandler.php

index e81b37d..0292af8 100644 (file)
@@ -142,7 +142,7 @@ class BitmapHandler extends TransformationalImageHandler {
                        $env['MAGICK_TMPDIR'] = $wgImageMagickTempDir;
                }
 
-               $rotation = $this->getRotation( $image );
+               $rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image );
                list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
 
                $cmd = call_user_func_array( 'wfEscapeShellArg', array_merge(
@@ -223,7 +223,7 @@ class BitmapHandler extends TransformationalImageHandler {
                                }
                        }
 
-                       $rotation = $this->getRotation( $image );
+                       $rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image );
                        list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
 
                        $im->setImageBackgroundColor( new ImagickPixel( 'white' ) );
@@ -344,7 +344,7 @@ class BitmapHandler extends TransformationalImageHandler {
 
                $src_image = call_user_func( $loader, $params['srcPath'] );
 
-               $rotation = function_exists( 'imagerotate' ) ? $this->getRotation( $image ) : 0;
+               $rotation = function_exists( 'imagerotate' ) && !isset( $params['disableRotation'] )  ? $this->getRotation( $image ) : 0;
                list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
                $dst_image = imagecreatetruecolor( $width, $height );
 
index 3e3be3d..b3ae296 100644 (file)
@@ -216,6 +216,12 @@ abstract class TransformationalImageHandler extends ImageHandler {
                # Transform functions and binaries need a FS source file
                $thumbnailSource = $this->getThumbnailSource( $image, $params );
 
+               // If the source isn't the original, disable EXIF rotation because it's already been applied
+               if ( $scalerParams['srcWidth'] != $thumbnailSource['width']
+                       || $scalerParams['srcHeight'] != $thumbnailSource['height'] ) {
+                       $scalerParams['disableRotation'] = true;
+               }
+
                $scalerParams['srcPath'] = $thumbnailSource['path'];
                $scalerParams['srcWidth'] = $thumbnailSource['width'];
                $scalerParams['srcHeight'] = $thumbnailSource['height'];