@@ -178,7 +178,7 @@ protected function process(string $action)
178178
179179 $ dest = $ create ($ this ->width , $ this ->height );
180180
181- // for png and webp we can actually preserve transparency
181+ // for png, webp and avif we can actually preserve transparency
182182 if (in_array ($ this ->image ()->imageType , $ this ->supportTransparency , true )) {
183183 imagealphablending ($ dest , false );
184184 imagesavealpha ($ dest , true );
@@ -222,7 +222,7 @@ public function save(?string $target = null, int $quality = 90): bool
222222
223223 $ this ->ensureResource ();
224224
225- // for png and webp we can actually preserve transparency
225+ // for png, webp and avif we can actually preserve transparency
226226 if (in_array ($ this ->image ()->imageType , $ this ->supportTransparency , true )) {
227227 imagepalettetotruecolor ($ this ->resource );
228228 imagealphablending ($ this ->resource , false );
@@ -270,6 +270,16 @@ public function save(?string $target = null, int $quality = 90): bool
270270 }
271271 break ;
272272
273+ case IMAGETYPE_AVIF :
274+ if (! function_exists ('imageavif ' )) {
275+ throw ImageException::forInvalidImageCreate (lang ('Images.avifNotSupported ' ));
276+ }
277+
278+ if (! @imageavif ($ this ->resource , $ target , $ quality )) {
279+ throw ImageException::forSaveFailed ();
280+ }
281+ break ;
282+
273283 default :
274284 throw ImageException::forInvalidImageCreate ();
275285 }
@@ -361,6 +371,13 @@ protected function getImageResource(string $path, int $imageType)
361371
362372 return imagecreatefromwebp ($ path );
363373
374+ case IMAGETYPE_AVIF :
375+ if (! function_exists ('imagecreatefromavif ' )) {
376+ throw ImageException::forInvalidImageCreate (lang ('Images.avifNotSupported ' ));
377+ }
378+
379+ return imagecreatefromavif ($ path );
380+
364381 default :
365382 throw ImageException::forInvalidImageCreate ('Ima ' );
366383 }
0 commit comments