/** * Re-orient an image using its embedded Exif profile orientation: * 1. Read the embedded exif data inside the image to determine it's orientation. * 2. Rotate and flip the image accordingly to re-orient it. * 3. Strip the Exif data from the image so that there can be no attempt to 'correct' it again. * * @param string $path * @param ImageInterface $image * @return ImageInterface $image */ protected function autoOrient($path, ImageInterface $image) { $exif = exif_read_data($path); if (isset($exif['Orientation'])) { switch ($exif['Orientation']) { case 2: $image->flipHorizontally(); break; case 3: $image->rotate(180); break; case 4: $image->flipVertically(); break; case 5: $image->flipVertically()->rotate(90); break; case 6: $image->rotate(90); break; case 7: $image->flipHorizontally()->rotate(90); break; case 8: $image->rotate(-90); break; } } return $image->strip(); }
/** * @param \Imagine\Image\ImageInterface $image * @return \Imagine\Image\ImageInterface */ protected function applyFlipVerticallyFilter(ImageInterface $image) { $image->flipVertically(); return $image; }
/** * {@inheritdoc} */ public function apply(ImageInterface $image) { return $image->flipVertically(); }
/** * Re-orient an image using its embedded Exif profile orientation: * 1. Attempt to read the embedded exif data inside the image to determine it's orientation. * if there is no exif data (i.e an exeption is thrown when trying to read it) then we'll * just return the image as is. * 2. If there is exif data, we'll rotate and flip the image accordingly to re-orient it. * 3. Finally, we'll strip the exif data from the image so that there can be no attempt to 'correct' it again. * * @param string $path * @param ImageInterface $image * * @return ImageInterface $image */ protected function autoOrient($path, ImageInterface $image) { if (function_exists('exif_read_data')) { try { $exif = exif_read_data($path); } catch (ErrorException $e) { return $image; } if (isset($exif['Orientation'])) { switch ($exif['Orientation']) { case 2: $image->flipHorizontally(); break; case 3: $image->rotate(180); break; case 4: $image->flipVertically(); break; case 5: $image->flipVertically()->rotate(90); break; case 6: $image->rotate(90); break; case 7: $image->flipHorizontally()->rotate(90); break; case 8: $image->rotate(-90); break; } } return $image->strip(); } else { return $image; } }