Skip to content

Commit

Permalink
Update exif data after orient() call for GD driver
Browse files Browse the repository at this point in the history
Set exif data of image to top-left orientation, marking the image as
aligned and making sure the rotation correction process is not
performed again.
  • Loading branch information
olivervogel committed May 11, 2024
1 parent 7a07db6 commit cca6bd3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Drivers/Gd/Modifiers/AlignRotationModifier.php
Expand Up @@ -12,7 +12,7 @@ class AlignRotationModifier extends GenericAlignRotationModifier implements Spec
{
public function apply(ImageInterface $image): ImageInterface
{
return match ($image->exif('IFD0.Orientation')) {
$image = match ($image->exif('IFD0.Orientation')) {
2 => $image->flop(),
3 => $image->rotate(180),
4 => $image->rotate(180)->flop(),
Expand All @@ -22,5 +22,29 @@ public function apply(ImageInterface $image): ImageInterface
8 => $image->rotate(90),
default => $image
};

return $this->markAligned($image);
}

/**
* Set exif data of image to top-left orientation, marking the image as
* aligned and making sure the rotation correction process is not
* performed again.
*
* @param ImageInterface $image
* @return ImageInterface
*/
private function markAligned(ImageInterface $image): ImageInterface
{
$exif = $image->exif()->map(function ($item) {
if (is_array($item) && array_key_exists('Orientation', $item)) {
$item['Orientation'] = 1;
return $item;
}

return $item;
});

return $image->setExif($exif);
}
}

0 comments on commit cca6bd3

Please sign in to comment.