1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 18:02:45 +02:00

Adds support for the AVIF format

This commit is contained in:
freshleafmedia
2020-11-12 08:51:24 +00:00
parent 032263954c
commit 9fb8364727
3 changed files with 46 additions and 0 deletions

View File

@@ -84,6 +84,13 @@ abstract class AbstractEncoder
*/ */
abstract protected function processWebp(); abstract protected function processWebp();
/**
* Processes and returns image as Avif encoded string
*
* @return string
*/
abstract protected function processAvif();
/** /**
* Process a given image * Process a given image
* *
@@ -169,6 +176,11 @@ abstract class AbstractEncoder
$this->result = $this->processWebp(); $this->result = $this->processWebp();
break; break;
case 'avif':
case 'image/avif':
$this->result = $this->processAvif();
break;
default: default:
throw new NotSupportedException( throw new NotSupportedException(
"Encoding format ({$format}) is not supported." "Encoding format ({$format}) is not supported."

View File

@@ -121,4 +121,16 @@ class Encoder extends \Intervention\Image\AbstractEncoder
"PSD format is not supported by Gd Driver." "PSD format is not supported by Gd Driver."
); );
} }
/**
* Processes and returns encoded image as AVIF string
*
* @return string
*/
protected function processAvif()
{
throw new NotSupportedException(
"AVIF format is not supported by Gd Driver."
);
}
} }

View File

@@ -170,4 +170,26 @@ class Encoder extends AbstractEncoder
return $imagick->getImagesBlob(); return $imagick->getImagesBlob();
} }
protected function processAvif()
{
if ( ! \Imagick::queryFormats('AVIF')) {
throw new NotSupportedException(
"AVIF format is not supported by Imagick installation."
);
}
$format = 'avif';
$compression = \Imagick::COMPRESSION_UNDEFINED;
$imagick = $this->image->getCore();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
return $imagick->getImagesBlob();
}
} }