Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add irot-based rotation support for AVIF images
Signed-off-by: JanisPlayer <[email protected]>
  • Loading branch information
JanisPlayer authored May 22, 2025
commit c5a560e56475d89eeb8793ef20069ed3e2b42eb3
27 changes: 27 additions & 0 deletions lib/private/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,34 @@ public function loadFromFile($imagePath = false) {
if (!$this->checkImageSize($imagePath)) {
return false;
}

$this->resource = @imagecreatefromavif($imagePath);

// Check for irot box and apply rotation if needed
if ($this->resource && function_exists('imagerotate')) {
$fp = fopen($imagePath, 'rb');
if ($fp) {
$data = fread($fp, 512);
fclose($fp);

if ($data !== false) {
$pos = strpos($data, 'irot');
if ($pos !== false && ($pos + 4 < strlen($data))) {
$rotationByte = ord($data[$pos + 4]);
$rotation = match ($rotationByte) {
1 => 90,
2 => 180,
3 => 270,
default => 0,
};
if ($rotation !== 0) {
$this->resource = imagerotate($this->resource, $rotation, 0);
}
}
}
}
}

} else {
$this->logger->debug('OC_Image->loadFromFile, AVIF images not supported: ' . $imagePath, ['app' => 'core']);
}
Expand Down