mirror of
https://github.com/Intervention/image.git
synced 2025-08-12 17:03:59 +02:00
Add quality parameter to AvifEncoder
This commit is contained in:
@@ -96,10 +96,10 @@ abstract class AbstractImage implements ImageInterface
|
|||||||
return $this->toBitmap($color_limit);
|
return $this->toBitmap($color_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toAvif(): EncodedImage
|
public function toAvif(int $quality = 75): EncodedImage
|
||||||
{
|
{
|
||||||
return $this->encode(
|
return $this->encode(
|
||||||
$this->resolveDriverClass('Encoders\AvifEncoder')
|
$this->resolveDriverClass('Encoders\AvifEncoder', $quality)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,11 @@ use Intervention\Image\Interfaces\ImageInterface;
|
|||||||
|
|
||||||
class AvifEncoder extends AbstractEncoder implements EncoderInterface
|
class AvifEncoder extends AbstractEncoder implements EncoderInterface
|
||||||
{
|
{
|
||||||
|
public function __construct(int $quality)
|
||||||
|
{
|
||||||
|
$this->quality = $quality;
|
||||||
|
}
|
||||||
|
|
||||||
public function encode(ImageInterface $image): EncodedImage
|
public function encode(ImageInterface $image): EncodedImage
|
||||||
{
|
{
|
||||||
$format = 'AVIF';
|
$format = 'AVIF';
|
||||||
@@ -20,6 +25,8 @@ class AvifEncoder extends AbstractEncoder implements EncoderInterface
|
|||||||
$imagick->setImageFormat($format);
|
$imagick->setImageFormat($format);
|
||||||
$imagick->setCompression($compression);
|
$imagick->setCompression($compression);
|
||||||
$imagick->setImageCompression($compression);
|
$imagick->setImageCompression($compression);
|
||||||
|
$imagick->setCompressionQuality($this->quality);
|
||||||
|
$imagick->setImageCompressionQuality($this->quality);
|
||||||
|
|
||||||
return new EncodedImage($imagick->getImagesBlob(), 'image/avif');
|
return new EncodedImage($imagick->getImagesBlob(), 'image/avif');
|
||||||
}
|
}
|
||||||
|
@@ -128,7 +128,7 @@ interface ImageInterface extends Traversable, Countable
|
|||||||
*
|
*
|
||||||
* @return EncodedImage
|
* @return EncodedImage
|
||||||
*/
|
*/
|
||||||
public function toAvif(): EncodedImage;
|
public function toAvif(int $quality = 75): EncodedImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode image to png format
|
* Encode image to png format
|
||||||
|
Reference in New Issue
Block a user