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);
}
}
}
}