From 32f8a93021fbca6f7388adf8748e87c8011d3ba9 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 26 Dec 2018 11:17:51 +0200 Subject: [PATCH] fix image --- application/Espo/EntryPoints/Image.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index 5a79c30830..ff10a62da9 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -55,6 +55,10 @@ class Image extends \Espo\Core\EntryPoints\Base 'xx-large' => array(1024, 1024), ); + protected $fixOrientationFileTypeList = [ + 'image/jpeg', + ]; + protected $allowedRelatedTypeList = null; protected $allowedFieldList = null; @@ -212,8 +216,21 @@ class Image extends \Espo\Core\EntryPoints\Base break; } + if (in_array($fileType, $this->fixOrientationFileTypeList)) { + $targetImage = $this->fixOrientation($targetImage, $filePath); + } + + return $targetImage; + } + + protected function fixOrientation($targetImage, $filePath) + { if (function_exists('exif_read_data')) { - $targetImage = imagerotate($targetImage, array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[@exif_read_data($filePath)['Orientation'] ?: 0], 0); + $orientation = @exif_read_data($filePath)['Orientation']; + if ($orientation) { + $angle = array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[$orientation]; + $targetImage = imagerotate($targetImage, $angle, 0); + } } return $targetImage;