1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 17:19:50 +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
return match ($image->exif('IFD0.Orientation')) {
2 => $image->flip(),
2 => $image->flop(),
3 => $image->rotate(180),
4 => $image->rotate(180)->flip(),
5 => $image->rotate(270)->flip(),
4 => $image->rotate(180)->flop(),
5 => $image->rotate(270)->flop(),
6 => $image->rotate(270),
7 => $image->rotate(90)->flip(),
7 => $image->rotate(90)->flop(),
8 => $image->rotate(90),
default => $image
};

View File

@@ -33,15 +33,34 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
// fix image orientation
switch ($imagick->getImageOrientation()) {
case Imagick::ORIENTATION_BOTTOMRIGHT:
case Imagick::ORIENTATION_TOPRIGHT: // 2
$imagick->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT: // 3
$imagick->rotateimage("#000", 180);
break;
case Imagick::ORIENTATION_RIGHTTOP:
$imagick->rotateimage("#000", 90);
case Imagick::ORIENTATION_BOTTOMLEFT: // 4
$imagick->rotateimage("#000", 180);
$imagick->flopImage();
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);
break;
}