From 27f6596a86e6c3a91e47f3a7d9212768ba23ad28 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Thu, 13 Nov 2014 11:26:15 +0100 Subject: [PATCH] Don't re-apply EXIF rotation to chained thumbnails Change-Id: I2f0674e4aea508ad7e00b7742a9d47bd0659e399 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/600 Bug: 67525 Bug: 73352 --- includes/media/Bitmap.php | 6 +++--- includes/media/TransformationalImageHandler.php | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index e81b37de37..0292af8bfa 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -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 ); diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index 3e3be3d110..b3ae296569 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -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']; -- 2.20.1