From 8d09ec98d5e0de55ed1aad10152a118096ef792f Mon Sep 17 00:00:00 2001 From: Anderson Entwistle <46688047+aentwist@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:59:42 -0400 Subject: [PATCH] feat: add AVIF support Signed-off-by: Anderson Entwistle <46688047+aentwist@users.noreply.github.com> --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Preview/Avif.php | 19 +++++++++++++++++++ lib/private/Preview/Generator.php | 2 ++ lib/private/PreviewManager.php | 2 ++ lib/private/legacy/OC_Image.php | 12 ++++++++++++ resources/config/mimetypemapping.dist.json | 1 + 7 files changed, 38 insertions(+) create mode 100644 lib/private/Preview/Avif.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 40d0c4f0cd1b2..fd3ee6ed7bed1 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1394,6 +1394,7 @@ 'OC\\OCS\\Result' => $baseDir . '/lib/private/OCS/Result.php', 'OC\\PreviewManager' => $baseDir . '/lib/private/PreviewManager.php', 'OC\\PreviewNotAvailableException' => $baseDir . '/lib/private/PreviewNotAvailableException.php', + 'OC\\Preview\\Avif' => $baseDir . '/lib/private/Preview/Avif.php', 'OC\\Preview\\BMP' => $baseDir . '/lib/private/Preview/BMP.php', 'OC\\Preview\\BackgroundCleanupJob' => $baseDir . '/lib/private/Preview/BackgroundCleanupJob.php', 'OC\\Preview\\Bitmap' => $baseDir . '/lib/private/Preview/Bitmap.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 65021f54adbba..7152b8f0f4a5b 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1427,6 +1427,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\OCS\\Result' => __DIR__ . '/../../..' . '/lib/private/OCS/Result.php', 'OC\\PreviewManager' => __DIR__ . '/../../..' . '/lib/private/PreviewManager.php', 'OC\\PreviewNotAvailableException' => __DIR__ . '/../../..' . '/lib/private/PreviewNotAvailableException.php', + 'OC\\Preview\\Avif' => __DIR__ . '/../../..' . '/lib/private/Preview/Avif.php', 'OC\\Preview\\BMP' => __DIR__ . '/../../..' . '/lib/private/Preview/BMP.php', 'OC\\Preview\\BackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Preview/BackgroundCleanupJob.php', 'OC\\Preview\\Bitmap' => __DIR__ . '/../../..' . '/lib/private/Preview/Bitmap.php', diff --git a/lib/private/Preview/Avif.php b/lib/private/Preview/Avif.php new file mode 100644 index 0000000000000..4fdfc7698c855 --- /dev/null +++ b/lib/private/Preview/Avif.php @@ -0,0 +1,19 @@ +defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ @@ -368,6 +369,7 @@ protected function registerCoreProviders() { $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); $this->registerCoreProvider(Preview\WebP::class, '/image\/webp/'); + $this->registerCoreProvider(Preview\Avif::class, '/image\/avif/'); $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); diff --git a/lib/private/legacy/OC_Image.php b/lib/private/legacy/OC_Image.php index 8deddcbba1bbf..06e60bcb2bf0b 100644 --- a/lib/private/legacy/OC_Image.php +++ b/lib/private/legacy/OC_Image.php @@ -397,6 +397,9 @@ public function data(): ?string { case "image/webp": $res = imagewebp($this->resource, null, $quality); break; + case "image/avif": + $res = imageavif($this->resource, null, $quality); + break; default: $res = imagepng($this->resource); $this->logger->info('OC_Image->data. Could not guess mime-type, defaulting to png', ['app' => 'core']); @@ -762,6 +765,15 @@ public function loadFromFile($imagePath = false) { $this->logger->debug('OC_Image->loadFromFile, webp images not supported: ' . $imagePath, ['app' => 'core']); } break; + case IMAGETYPE_AVIF: + if (imagetypes() & IMG_AVIF) { + if (!$this->checkImageSize($imagePath)) return false; + + $this->resource = imagecreatefromavif($imagePath); + } else { + $this->logger->debug("OC_Image->loadFromFile: installation does not support AVIF; got $imagePath", ['app' => 'core']); + } + break; /* case IMAGETYPE_TIFF_II: // (intel byte order) break; diff --git a/resources/config/mimetypemapping.dist.json b/resources/config/mimetypemapping.dist.json index 7b631466972fd..4ce98da05a734 100644 --- a/resources/config/mimetypemapping.dist.json +++ b/resources/config/mimetypemapping.dist.json @@ -16,6 +16,7 @@ "arw": ["image/x-dcraw"], "asciidoc": ["text/asciidoc", "text/plain"], "avi": ["video/x-msvideo"], + "avif": ["image/avif"], "bash": ["text/x-shellscript"], "bat": ["application/x-msdos-program"], "bin": ["application/x-bin"],