1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-01 11:30:16 +02:00

Fix image orientation from exif data with Imagick

This commit is contained in:
Oliver Vogel
2023-10-27 16:02:19 +02:00
parent 49cf5f51ae
commit c05d3647e4

View File

@@ -26,6 +26,24 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
$imagick->readImageBlob($input);
$imagick = $imagick->coalesceImages();
// fix image orientation
switch ($imagick->getImageOrientation()) {
case Imagick::ORIENTATION_BOTTOMRIGHT:
$imagick->rotateimage("#000", 180);
break;
case Imagick::ORIENTATION_RIGHTTOP:
$imagick->rotateimage("#000", 90);
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$imagick->rotateimage("#000", -90);
break;
}
// set new orientation in image
$imagick->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$image = new Image($imagick);
$image->setLoops($imagick->getImageIterations());
$image->setExif($this->decodeExifData($input));