EXIF orientation rotation code adjustments #556
This commit is contained in:
parent
55628f1f56
commit
9bfa149d29
@ -484,59 +484,58 @@ final class Photo {
|
|||||||
|
|
||||||
$orientation = $image->getImageOrientation();
|
$orientation = $image->getImageOrientation();
|
||||||
|
|
||||||
// Check if the images needs to be adjusted at all
|
switch ($orientation) {
|
||||||
if ($orientation!==Imagick::ORIENTATION_TOPLEFT) {
|
|
||||||
|
|
||||||
switch ($orientation) {
|
case Imagick::ORIENTATION_TOPLEFT:
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_TOPLEFT:
|
case Imagick::ORIENTATION_TOPRIGHT:
|
||||||
break;
|
$image->flopImage();
|
||||||
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_TOPRIGHT:
|
case Imagick::ORIENTATION_BOTTOMRIGHT:
|
||||||
$image->flopImage();
|
$image->rotateImage(new ImagickPixel(), 180);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_BOTTOMRIGHT:
|
case Imagick::ORIENTATION_BOTTOMLEFT:
|
||||||
$image->rotateImage(new ImagickPixel(), 180);
|
$image->flopImage();
|
||||||
break;
|
$image->rotateImage(new ImagickPixel(), 180);
|
||||||
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_BOTTOMLEFT:
|
case Imagick::ORIENTATION_LEFTTOP:
|
||||||
$image->flopImage();
|
$image->flopImage();
|
||||||
$image->rotateImage(new ImagickPixel(), 180);
|
$image->rotateImage(new ImagickPixel(), -90);
|
||||||
break;
|
$swapSize = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_LEFTTOP:
|
case Imagick::ORIENTATION_RIGHTTOP:
|
||||||
$image->flopImage();
|
$image->rotateImage(new ImagickPixel(), 90);
|
||||||
$image->rotateImage(new ImagickPixel(), -90);
|
$swapSize = true;
|
||||||
$swapSize = true;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Imagick::ORIENTATION_RIGHTTOP:
|
case Imagick::ORIENTATION_RIGHTBOTTOM:
|
||||||
$image->rotateImage(new ImagickPixel(), 90);
|
$image->flopImage();
|
||||||
$swapSize = true;
|
$image->rotateImage(new ImagickPixel(), 90);
|
||||||
break;
|
$swapSize = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case Imagick::ORIENTATION_RIGHTBOTTOM:
|
case Imagick::ORIENTATION_LEFTBOTTOM:
|
||||||
$image->flopImage();
|
$image->rotateImage(new ImagickPixel(), -90);
|
||||||
$image->rotateImage(new ImagickPixel(), 90);
|
$swapSize = true;
|
||||||
$swapSize = true;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Imagick::ORIENTATION_LEFTBOTTOM:
|
default:
|
||||||
$image->rotateImage(new ImagickPixel(), -90);
|
return false;
|
||||||
$swapSize = true;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
|
|
||||||
$image->writeImage($path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust photo
|
||||||
|
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
|
||||||
|
$image->writeImage($path);
|
||||||
|
|
||||||
|
// Free memory
|
||||||
$image->clear();
|
$image->clear();
|
||||||
$image->destroy();
|
$image->destroy();
|
||||||
|
|
||||||
@ -548,6 +547,11 @@ final class Photo {
|
|||||||
|
|
||||||
switch ($info['orientation']) {
|
switch ($info['orientation']) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
// do nothing
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// mirror
|
// mirror
|
||||||
// not yet implemented
|
// not yet implemented
|
||||||
@ -597,6 +601,7 @@ final class Photo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recreate photo
|
// Recreate photo
|
||||||
|
// In this step the photos also loses its metadata :(
|
||||||
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
|
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
|
||||||
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
|
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
|
||||||
imagejpeg($newSourceImg, $path, 100);
|
imagejpeg($newSourceImg, $path, 100);
|
||||||
|
Loading…
Reference in New Issue
Block a user