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,37 +472,66 @@ final class Photo {
if (extension_loaded('imagick')&&Settings::get()['imagick']==='1') {
switch ($info['orientation']) {
$image = new Imagick();
$image->readImage($path);
case 3:
$rotateImage = 180;
$orientation = $image->getImageOrientation();
// Check if the images needs to be adjusted at all
if ($orientation!==Imagick::ORIENTATION_TOPLEFT) {
switch ($orientation) {
case Imagick::ORIENTATION_TOPLEFT:
break;
case 6:
$rotateImage = 90;
case Imagick::ORIENTATION_TOPRIGHT:
$image->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateImage(new ImagickPixel(), 180);
break;
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 8:
$rotateImage = 270;
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:
return false;
break;
}
if ($rotateImage!==0) {
$image = new Imagick();
$image->readImage($path);
$image->rotateImage(new ImagickPixel(), $rotateImage);
$image->setImageOrientation(1);
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image->writeImage($path);
}
$image->clear();
$image->destroy();
}
} else {