Skip to content

Commit

Permalink
add avif support
Browse files Browse the repository at this point in the history
closes #260

Signed-off-by: bnomei <b@bnomei.com>
  • Loading branch information
bnomei committed Feb 20, 2023
1 parent 82dbef9 commit 6b3bbf1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/examples export-ignore
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/claviska/SimpleImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6b3bbf1

Please sign in to comment.