exif('IFD0.Orientation')) { 2 => $image->flop(), 3 => $image->rotate(180), 4 => $image->rotate(180)->flop(), 5 => $image->rotate(270)->flop(), 6 => $image->rotate(270), 7 => $image->rotate(90)->flop(), 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); } }