mirror of
https://github.com/humhub/humhub.git
synced 2025-03-14 20:19:47 +01:00
Merge pull request #4152 from humhub/fix/4113
Fix #4036: Profile images are not rotated correctly
This commit is contained in:
commit
13d274a6e8
@ -3,6 +3,7 @@ HumHub Change Log
|
||||
|
||||
1.5.3 (Unreleased)
|
||||
--------------------
|
||||
- Fix #4036: Profile images are not rotated correctly
|
||||
- Fix #4168: Erroneous pagination in notification overview
|
||||
- Fix #4060: Profile description and text regex error message not translatable
|
||||
- Fix #4153: Administration: Email transport configuration 'Save & Test' Gives No Result
|
||||
|
@ -10,6 +10,7 @@ namespace humhub\libs;
|
||||
|
||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
use humhub\modules\content\models\ContentContainer;
|
||||
use humhub\modules\file\libs\ImageHelper;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\widgets\Image as SpaceImage;
|
||||
use humhub\modules\user\widgets\Image as UserImage;
|
||||
@ -173,11 +174,16 @@ class ProfileImage
|
||||
if ($file instanceof UploadedFile) {
|
||||
$file = $file->tempName;
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
|
||||
// Make sure original file is max. 800 width
|
||||
// Convert image to uploaded JPEG, fix orientation and remove additional meta information
|
||||
$image = Image::getImagine()->open($file);
|
||||
ImageHelper::fixJpegOrientation($image, $file);
|
||||
$image->thumbnail($image->getSize())
|
||||
->save($this->getPath('_org'), ['format' => 'jpg']);
|
||||
|
||||
// Make sure original file is max. 800 width
|
||||
$image = Image::getImagine()->open($this->getPath('_org'));
|
||||
if ($image->getSize()->getWidth() > 800) {
|
||||
$image->resize($image->getSize()->widen(800));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace humhub\modules\file\converter;
|
||||
|
||||
use humhub\modules\file\libs\ImageHelper;
|
||||
use Imagine\Image\ImageInterface;
|
||||
use Yii;
|
||||
use humhub\modules\file\models\File;
|
||||
@ -80,25 +81,7 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImageHelper::fixJpegOrientation($image, $this->file);
|
||||
|
||||
if ($image->getSize()->getHeight() > $this->options['height']) {
|
||||
$image->resize($image->getSize()->heighten($this->options['height']));
|
||||
|
59
protected/humhub/modules/file/libs/ImageHelper.php
Normal file
59
protected/humhub/modules/file/libs/ImageHelper.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\file\libs;
|
||||
|
||||
|
||||
use humhub\modules\file\models\File;
|
||||
use Imagine\Image\ImageInterface;
|
||||
|
||||
/**
|
||||
* Class ImageHelper
|
||||
*
|
||||
* @since 1.5.2
|
||||
* @package humhub\modules\file\libs
|
||||
*/
|
||||
class ImageHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Fix orientation of JPEG images based on EXIF information
|
||||
*
|
||||
* @see https://github.com/yiisoft/yii2-imagine/issues/44
|
||||
* @param $image ImageInterface
|
||||
* @param $file File|string
|
||||
* @throws \yii\base\InvalidConfigException
|
||||
*/
|
||||
public static function fixJpegOrientation($image, $file)
|
||||
{
|
||||
$mimeType = '';
|
||||
if ($file instanceof File) {
|
||||
$mimeType = $file->mime_type;
|
||||
$file = $file->store->get();
|
||||
} elseif (is_string($file) && file_exists($file)) {
|
||||
$mimeType = FileHelper::getMimeType($file);
|
||||
}
|
||||
|
||||
if ($mimeType === 'image/jpeg' && function_exists('exif_read_data')) {
|
||||
$exif = @exif_read_data($file);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user