EXIF orientation rotation code adjustments #556

This commit is contained in:
Tobias Reich 2016-06-11 15:55:05 +02:00
parent 55628f1f56
commit 9bfa149d29

View File

@ -484,12 +484,10 @@ final class Photo {
$orientation = $image->getImageOrientation(); $orientation = $image->getImageOrientation();
// Check if the images needs to be adjusted at all
if ($orientation!==Imagick::ORIENTATION_TOPLEFT) {
switch ($orientation) { switch ($orientation) {
case Imagick::ORIENTATION_TOPLEFT: case Imagick::ORIENTATION_TOPLEFT:
return false;
break; break;
case Imagick::ORIENTATION_TOPRIGHT: case Imagick::ORIENTATION_TOPRIGHT:
@ -528,15 +526,16 @@ final class Photo {
break; break;
default: default:
return false;
break; break;
} }
// Adjust photo
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT); $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image->writeImage($path); $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);