Improved orientation-handling with Imagick #556

This commit is contained in:
Tobias Reich 2016-06-05 15:47:41 +02:00
parent 70cd7f8a47
commit a9cfa87fd2

View File

@ -472,38 +472,67 @@ final class Photo {
if (extension_loaded('imagick')&&Settings::get()['imagick']==='1') { if (extension_loaded('imagick')&&Settings::get()['imagick']==='1') {
switch ($info['orientation']) { $image = new Imagick();
$image->readImage($path);
case 3: $orientation = $image->getImageOrientation();
$rotateImage = 180;
break;
case 6: // Check if the images needs to be adjusted at all
$rotateImage = 90; if ($orientation!==Imagick::ORIENTATION_TOPLEFT) {
$swapSize = true;
break;
case 8: switch ($orientation) {
$rotateImage = 270;
$swapSize = true;
break;
default: case Imagick::ORIENTATION_TOPLEFT:
return false; break;
break;
} case Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;
if ($rotateImage!==0) { case Imagick::ORIENTATION_BOTTOMRIGHT:
$image = new Imagick(); $image->rotateImage(new ImagickPixel(), 180);
$image->readImage($path); break;
$image->rotateImage(new ImagickPixel(), $rotateImage);
$image->setImageOrientation(1); case Imagick::ORIENTATION_BOTTOMLEFT:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), 180);
break;
case Imagick::ORIENTATION_LEFTTOP:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), -90);
$swapSize = true;
break;
case Imagick::ORIENTATION_RIGHTTOP:
$image->rotateImage(new ImagickPixel(), 90);
$swapSize = true;
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$image->flopImage();
$image->rotateImage(new ImagickPixel(), 90);
$swapSize = true;
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage(new ImagickPixel(), -90);
$swapSize = true;
break;
default:
break;
}
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image->writeImage($path); $image->writeImage($path);
$image->clear();
$image->destroy();
} }
$image->clear();
$image->destroy();
} else { } else {
$newWidth = $info['width']; $newWidth = $info['width'];