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
Next Next commit
experimental default format for AVIF is JPEG
_output() is maybe useless
WebP have longer time to encode as PNG and JPEG, maybe remove it too by default for WebP.

Signed-off-by: JanisPlayer <[email protected]>
  • Loading branch information
JanisPlayer authored Sep 11, 2023
commit 0710c149808d7fa5744e0ff092179d82456262d0
44 changes: 35 additions & 9 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private function _output(?string $filePath = null, ?string $mimeType = null): bo
$imageType = IMAGETYPE_WEBP;
break;
case 'image/avif':
$imageType = IMAGETYPE_AVIF;
$imageType = IMAGETYPE_JPEG;
break;
case 'image/png':
$imageType = IMAGETYPE_PNG;
Expand All @@ -296,6 +296,19 @@ private function _output(?string $filePath = null, ?string $mimeType = null): bo
}
}

if ($this->mimeType !== 'image/gif') {
$preview_format = $this->config->getSystemValueString('preview_format', '');
switch ($preview_format) {
case 'webp':
$imageType = IMAGETYPE_WEBP;
break;
case 'avif':
$imageType = IMAGETYPE_AVIF;

Check failure

Code scanning / Psalm

UndefinedConstant

Const IMAGETYPE_AVIF is not defined
break;
default:
}
}

switch ($imageType) {
case IMAGETYPE_GIF:
$retVal = imagegif($this->resource, $filePath);
Expand All @@ -307,7 +320,7 @@ private function _output(?string $filePath = null, ?string $mimeType = null): bo
break;
case "image/webp":
/** @psalm-suppress InvalidScalarArgument */
imageinterlace($this->resource, (PHP_VERSION_ID >= 80100 ? true : 1));
imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1));
$retVal = imagewebp($this->resource, $filePath, $this->getWebpQuality());
break;
case "image/avif":
Expand Down Expand Up @@ -379,15 +392,12 @@ public function dataMimeType(): ?string {
}

if ($this->mimeType !== 'image/gif') {
$preview_format = $this->config->getSystemValueString('preview_format', 'jpeg');

switch ($preview_format) { // Change the format to the correct one
$preview_format = $this->config->getSystemValueString('preview_format', '');
switch ($preview_format) {
case 'webp':
return 'image/webp';
break;
case 'avif':
return 'image/avif';
break;
default:
}
}
Expand All @@ -413,7 +423,23 @@ public function data(): ?string {
return null;
}
ob_start();
switch ($this->mimeType) {
$imageType = $this->imageType;
if ($imageType == 'image/avif') {
$imageType = 'image/jpeg';
}
if ($imageType !== 'image/gif') {
$preview_format = $this->config->getSystemValueString('preview_format', '');
switch ($preview_format) {
case 'webp':
$imageType = 'image/webp';
break;
case 'avif':
$imageType = 'image/avif';
break;
default:
}
}
switch ($imageType) {
case "image/png":
$res = imagepng($this->resource);
break;
Expand All @@ -425,7 +451,7 @@ public function data(): ?string {
break;
case "image/webp":
/** @psalm-suppress InvalidScalarArgument */
imageinterlace($this->resource, (PHP_VERSION_ID >= 80100 ? true : 1));
imageinterlace($this->resource, (PHP_VERSION_ID >= 80000 ? true : 1));
$res = imagewebp($this->resource, null, $this->getWebpQuality());
break;
case "image/avif":
Expand Down