1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 09:52:59 +02:00

Fix image auto orientation

This commit is contained in:
Oliver Vogel
2024-01-08 10:53:13 +01:00
parent 2b03a4c2a2
commit 72680e8138
2 changed files with 27 additions and 8 deletions

View File

@@ -61,12 +61,12 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
// fix image orientation // fix image orientation
return match ($image->exif('IFD0.Orientation')) { return match ($image->exif('IFD0.Orientation')) {
2 => $image->flip(), 2 => $image->flop(),
3 => $image->rotate(180), 3 => $image->rotate(180),
4 => $image->rotate(180)->flip(), 4 => $image->rotate(180)->flop(),
5 => $image->rotate(270)->flip(), 5 => $image->rotate(270)->flop(),
6 => $image->rotate(270), 6 => $image->rotate(270),
7 => $image->rotate(90)->flip(), 7 => $image->rotate(90)->flop(),
8 => $image->rotate(90), 8 => $image->rotate(90),
default => $image default => $image
}; };

View File

@@ -33,15 +33,34 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
// fix image orientation // fix image orientation
switch ($imagick->getImageOrientation()) { switch ($imagick->getImageOrientation()) {
case Imagick::ORIENTATION_BOTTOMRIGHT: case Imagick::ORIENTATION_TOPRIGHT: // 2
$imagick->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT: // 3
$imagick->rotateimage("#000", 180); $imagick->rotateimage("#000", 180);
break; break;
case Imagick::ORIENTATION_RIGHTTOP: case Imagick::ORIENTATION_BOTTOMLEFT: // 4
$imagick->rotateimage("#000", 90); $imagick->rotateimage("#000", 180);
$imagick->flopImage();
break; break;
case Imagick::ORIENTATION_LEFTBOTTOM: case Imagick::ORIENTATION_LEFTTOP: // 5
$imagick->rotateimage("#000", -270);
$imagick->flopImage();
break;
case Imagick::ORIENTATION_RIGHTTOP: // 6
$imagick->rotateimage("#000", -270);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM: // 7
$imagick->rotateimage("#000", -90);
$imagick->flopImage();
break;
case Imagick::ORIENTATION_LEFTBOTTOM: // 8
$imagick->rotateimage("#000", -90); $imagick->rotateimage("#000", -90);
break; break;
} }