From 6b3bbf155bb4d65643ed38843cd52e800a51d658 Mon Sep 17 00:00:00 2001 From: Bruno Meilick Date: Mon, 20 Feb 2023 15:25:50 +0000 Subject: [PATCH] add avif support closes #260 Signed-off-by: bnomei --- .gitattributes | 4 ++++ README.md | 2 +- src/claviska/SimpleImage.php | 13 ++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..516226e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +/examples export-ignore +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/README.md b/README.md index ffabe9d..e23aed8 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ try { ## Features -- Supports reading, writing, and converting GIF, JPEG, PNG, WEBP, BMP formats. +- Supports reading, writing, and converting GIF, JPEG, PNG, WEBP, BMP, AVIF formats. - Reads and writes files, data URIs, and image strings. - Manipulation: crop, resize, overlay/watermark, adding TTF text - Drawing: arc, border, dot, ellipse, line, polygon, rectangle, rounded rectangle diff --git a/src/claviska/SimpleImage.php b/src/claviska/SimpleImage.php index 7c95316..abb2fd6 100644 --- a/src/claviska/SimpleImage.php +++ b/src/claviska/SimpleImage.php @@ -316,7 +316,18 @@ protected function generate($mimeType = null, $quality = 100) { ); } imageinterlace($this->image, true); - imagebmp($this->image, null, $quality); + imagebmp($this->image, null, $quality < 100); + break; + case 'image/avif': + // Not all versions of PHP support avif + if(!function_exists('imageavif')) { + throw new \Exception( + 'AVIF support is not available in your version of PHP.', + self::ERR_UNSUPPORTED_FORMAT + ); + } + imageinterlace($this->image, true); + imageavif($this->image, null, $quality); break; default: throw new \Exception('Unsupported format: ' . $mimeType, self::ERR_UNSUPPORTED_FORMAT);