Rotate JPEG images if they have an Orientation tag

This commit is contained in:
Will Franklin
2023-08-24 15:41:24 +01:00
parent 8c2702be96
commit 28f5677247

View File

@@ -24,8 +24,26 @@ class ImageController implements ContentController
case 17: $ext = 'ico';break; // ico
case 18: $ext = 'webp';break; // webp
case 2: //we clean up exif data of JPGs so GPS and other data is removed
case 2:
//we clean up exif data of JPGs so GPS and other data is removed
$res = imagecreatefromjpeg($tmpfile);
// rotate based on EXIF Orientation
$exif = exif_read_data($tmpfile);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$res = imagerotate($res, 180, 0);
break;
case 6:
$res = imagerotate($res, -90, 0);
break;
case 8:
$res = imagerotate($res, 90, 0);
break;
}
}
imagejpeg($res, $tmpfile, (defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90));
$ext = 'jpg';
break;