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();
// Check if the images needs to be adjusted at all
if ($orientation!==Imagick::ORIENTATION_TOPLEFT) {
switch ($orientation) {
case Imagick::ORIENTATION_TOPLEFT:
return false;
break;
case Imagick::ORIENTATION_TOPRIGHT:
@ -528,15 +526,16 @@ final class Photo {
break;
default:
return false;
break;
}
// Adjust photo
$image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image->writeImage($path);
}
// Free memory
$image->clear();
$image->destroy();
@ -548,6 +547,11 @@ final class Photo {
switch ($info['orientation']) {
case 1:
// do nothing
return false;
break;
case 2:
// mirror
// not yet implemented
@ -597,6 +601,7 @@ final class Photo {
}
// Recreate photo
// In this step the photos also loses its metadata :(
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
imagejpeg($newSourceImg, $path, 100);