Fix #4036: Uploaded photos are not rotated correctly

This commit is contained in:
Lucas Bartholemy 2020-05-05 17:07:34 +02:00
parent 28e30ff566
commit 2ee4ad850b
3 changed files with 23 additions and 14 deletions

View File

@ -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)
----------------------

View File

@ -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']);
}
}
}
/**

View File

@ -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()
{