Skip to content

Commit

Permalink
Disable auto rotate for HEIF images in imaginary. Issue #662
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdelellis committed Aug 15, 2023
1 parent 9767670 commit ccfeebe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
42 changes: 26 additions & 16 deletions lib/Helper/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,24 @@ public function getInfo(string $filepath): array {
}

$info = json_decode($response->getBody(), true);

$type = $info['type'];
//NOTE: Imaginary has problems rorating heic images. Issue #662
$autorotate = ($info['orientation'] > 4 && $type != 'heif');

return [
'type' => $type,
'autorotate' => $autorotate,
// Rotates the size, since it is important and Imaginary do not do that.
'width' => $info['orientation'] < 5 ? $info['width'] : $info['height'],
'height' => $info['orientation'] < 5 ? $info['height'] : $info['width']
'width' => $autorotate ? $info['height'] : $info['width'],
'height' => $autorotate ? $info['width'] : $info['height']
];
}

/**
* @return string|resource Returns the resized image
*/
public function getResized(string $filepath, int $width, int $height, string $mimeType) {
public function getResized(string $filepath, int $width, int $height, bool $autorotate, string $mimeType) {

$imaginaryUrl = $this->config->getSystemValueString('preview_imaginary_url', 'invalid');
$imaginaryUrl = rtrim($imaginaryUrl, '/');
Expand All @@ -96,20 +103,23 @@ public function getResized(string $filepath, int $width, int $height, string $mi
$type = 'jpeg';
}

$operations = [
[
$operations = [];

if ($autorotate) {
$operations[] = [
'operation' => 'autorotate',
],
[
'operation' => 'resize',
'params' => [
'width' => $width,
'height' => $height,
'stripmeta' => 'true',
'type' => $type,
'norotation' => 'true',
'force' => 'true'
]
];
}

$operations[] = [
'operation' => 'resize',
'params' => [
'width' => $width,
'height' => $height,
'stripmeta' => 'true',
'type' => $type,
'norotation' => 'true',
'force' => 'true'
]
];

Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/TempImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function prepareImage() {
$newWidth = intval(round($widthOrig * $scaleFactor));
$newHeight = intval(round($heightOrig * $scaleFactor));

$resizedResource = $this->imaginary->getResized($this->imagePath, $newWidth, $newHeight, $this->preferredMimeType);
$resizedResource = $this->imaginary->getResized($this->imagePath, $newWidth, $newHeight, $fileInfo['autorotate'], $this->preferredMimeType);
$this->loadFromData($resizedResource);

if (!$this->valid()) {
Expand Down

0 comments on commit ccfeebe

Please sign in to comment.