Webiny\Component\Image\ImageLoader::fixImageOrientation PHP Method

fixImageOrientation() private static method

This method fixes that. Method is called automatically on the open method.
private static fixImageOrientation ( File $imageFile, Webiny\Component\Image\ImageInterface $image )
$imageFile Webiny\Component\Storage\File\File
$image Webiny\Component\Image\ImageInterface
    private static function fixImageOrientation(File $imageFile, ImageInterface $image)
    {
        $format = $image->getFormat();
        // exif data is available only on jpeg and tiff
        // tiff is ignored, because smartphones don't produce tiff images
        if ($format == 'jpg' || $format == 'jpeg') {
            $exifData = exif_read_data($imageFile->getAbsolutePath(), 'IFDO');
            if (isset($exifData['Orientation'])) {
                switch ($exifData['Orientation']) {
                    case 3:
                        $rotation = 180;
                        break;
                    case 6:
                        $rotation = 90;
                        break;
                    case 8:
                        $rotation = -90;
                        break;
                    default:
                        $rotation = 0;
                        break;
                }
                if ($rotation != 0) {
                    $image->rotate($rotation);
                }
            }
        }
    }