diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index f0f51464b6..1b29641f28 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -7,7 +7,7 @@ HumHub Change Log - Fix #4031: Notifications with non existing base model breaks notification list - Fix #4038: Cannot use yii\helpers\Html as Html because the name is already in use in ProfileBannerImage - Fix #4050: Broken Cron-job documentation link used in cron info sidebar snippet - +- Fix #4036: Uploaded photos are not rotated correctly 1.5.1 (April 19, 2020) ---------------------- diff --git a/protected/humhub/modules/file/components/StorageManager.php b/protected/humhub/modules/file/components/StorageManager.php index abd54e05e8..4319886278 100644 --- a/protected/humhub/modules/file/components/StorageManager.php +++ b/protected/humhub/modules/file/components/StorageManager.php @@ -79,17 +79,7 @@ class StorageManager extends Component implements StorageManagerInterface if (is_uploaded_file($file->tempName)) { move_uploaded_file($file->tempName, $this->get($variant)); @chmod($this->get($variant), $this->fileMode); - - /** - * For uploaded jpeg files convert them again - to handle special - * exif attributes (e.g. orientation) - */ - if ($file->type === 'image/jpeg') { - Image::getImagine()->open($this->get($variant))->save($this->get($variant), ['format' => 'jpg']); - } } - - } /** diff --git a/protected/humhub/modules/file/converter/PreviewImage.php b/protected/humhub/modules/file/converter/PreviewImage.php index ba63fd5005..f2c03da21d 100644 --- a/protected/humhub/modules/file/converter/PreviewImage.php +++ b/protected/humhub/modules/file/converter/PreviewImage.php @@ -81,6 +81,25 @@ class PreviewImage extends BaseConverter if (!is_file($this->file->store->get($fileName))) { $image = Image::getImagine()->open($this->file->store->get()); + // Also handle orientation of resized images + // https://github.com/yiisoft/yii2-imagine/issues/44 + if ($this->file->mime_type === 'image/jpeg' && function_exists('exif_read_data')) { + $exif = exif_read_data($this->file->store->get()); + if (!empty($exif['Orientation'])) { + switch ($exif['Orientation']) { + case 3: + $image->rotate(180); + break; + case 6: + $image->rotate(90); + break; + case 8: + $image->rotate(-90); + break; + } + } + } + if ($image->getSize()->getHeight() > $this->options['height']) { $image->resize($image->getSize()->heighten($this->options['height'])); } @@ -116,8 +135,8 @@ class PreviewImage extends BaseConverter } /** - * @deprecated since 1.5 * @return int the image width or 0 if not valid + * @deprecated since 1.5 */ public function getWidth() { @@ -128,8 +147,8 @@ class PreviewImage extends BaseConverter } /** - * @deprecated since 1.5 * @return int the image height or 0 if not valid + * @deprecated since 1.5 */ public function getHeight() { @@ -140,8 +159,8 @@ class PreviewImage extends BaseConverter } /** - * @deprecated since 1.5 * @return ImageInterface + * @deprecated since 1.5 */ public function getImage() {