diff --git a/application/config/config.ini.changeme b/application/config/config.ini.changeme index 743d81bfe0..e73e925692 100644 --- a/application/config/config.ini.changeme +++ b/application/config/config.ini.changeme @@ -265,6 +265,7 @@ mail.transport.type = "Sendmail" ; ; fileDerivatives.strategyOptions.page = "0" ; fileDerivatives.strategyOptions.gravity = "center" +; fileDerivatives.strategyOptions.autoOrient = false ; fileDerivatives.typeWhitelist[] ; If set, Omeka will only attempt to create derivatives for files with the diff --git a/application/libraries/Omeka/File/Derivative/Strategy/ExternalImageMagick.php b/application/libraries/Omeka/File/Derivative/Strategy/ExternalImageMagick.php index c32d6295aa..e2237cc781 100644 --- a/application/libraries/Omeka/File/Derivative/Strategy/ExternalImageMagick.php +++ b/application/libraries/Omeka/File/Derivative/Strategy/ExternalImageMagick.php @@ -96,7 +96,12 @@ protected function _getConvertArgs($type, $constraint) $version = $this->getOption('version', '0'); if ($type != 'square_thumbnail') { - return '-background white +repage -flatten -thumbnail ' . escapeshellarg("{$constraint}x{$constraint}>"); + $args = array( + '-background white', + '+repage', + '-flatten', + '-thumbnail ' . escapeshellarg("{$constraint}x{$constraint}>") + ); } else { $gravity = $this->getOption('gravity', 'Center'); // Native square thumbnail resize requires at least version 6.3.8-3. @@ -123,8 +128,12 @@ protected function _getConvertArgs($type, $constraint) '+repage' ); } - return join (' ', $args); } + + if ($this->getOption('autoOrient', false)) { + array_unshift($args, '-auto-orient'); + } + return join (' ', $args); } /** diff --git a/application/libraries/Omeka/File/Derivative/Strategy/Imagick.php b/application/libraries/Omeka/File/Derivative/Strategy/Imagick.php index 677e5ec57f..005a0c8c2e 100644 --- a/application/libraries/Omeka/File/Derivative/Strategy/Imagick.php +++ b/application/libraries/Omeka/File/Derivative/Strategy/Imagick.php @@ -41,6 +41,10 @@ public function createImage($sourcePath, $destPath, $type, $sizeConstraint, $mim return false; } + if ($this->getOption('autoOrient', false)) { + $this->_autoOrient($imagick); + } + $origX = $imagick->getImageWidth(); $origY = $imagick->getImageHeight(); @@ -137,4 +141,39 @@ protected function _getCropOffsetY($resizedY, $sizeConstraint) return (int) (($resizedY - $sizeConstraint) / 2); } } + + protected function _autoOrient($imagick) + { + $orientation = $imagick->getImageOrientation(); + $white = new ImagickPixel('#fff'); + switch ($orientation) { + case Imagick::ORIENTATION_RIGHTTOP: + $imagick->rotateImage($white, 90); + break; + case Imagick::ORIENTATION_BOTTOMRIGHT: + $imagick->rotateImage($white, 180); + break; + case Imagick::ORIENTATION_LEFTBOTTOM: + $imagick->rotateImage($white, 270); + break; + case Imagick::ORIENTATION_TOPRIGHT: + $imagick->flopImage(); + break; + case Imagick::ORIENTATION_RIGHTBOTTOM: + $imagick->flopImage(); + $imagick->rotateImage($white, 90); + break; + case Imagick::ORIENTATION_BOTTOMLEFT: + $imagick->flopImage(); + $imagick->rotateImage($white, 180); + break; + case Imagick::ORIENTATION_LEFTTOP: + $imagick->flopImage(); + $imagick->rotateImage($white, 270); + break; + case Imagick::ORIENTATION_TOPLEFT: + default: + break; + } + } }