1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-23 05:52:47 +02:00

Merge pull request #1113 from gijsdev/gd-avif

GD AVIF support
This commit is contained in:
Oliver Vogel
2021-10-03 16:17:12 +02:00
committed by GitHub
2 changed files with 28 additions and 13 deletions

View File

@@ -147,9 +147,23 @@ class Encoder extends \Intervention\Image\AbstractEncoder
*/ */
protected function processAvif() protected function processAvif()
{ {
throw new NotSupportedException( if ( ! function_exists('imageavif')) {
"AVIF format is not supported by Gd Driver." throw new NotSupportedException(
); "AVIF format is not supported by PHP installation."
);
}
ob_start();
$resource = $this->image->getCore();
imagepalettetotruecolor($resource);
imagealphablending($resource, true);
imagesavealpha($resource, true);
imageavif($resource, null, $this->quality);
$this->image->mime = defined('IMAGETYPE_AVIF') ? image_type_to_mime_type(IMAGETYPE_AVIF) : 'image/avif';
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
} }
/** /**

View File

@@ -60,7 +60,7 @@ class EncoderTest extends TestCase
$this->assertEquals('image/webp; charset=binary', $this->getMime($encoder->result)); $this->assertEquals('image/webp; charset=binary', $this->getMime($encoder->result));
} }
} }
public function testProcessWebpGdWithUnSupportedPalette() public function testProcessWebpGdWithUnSupportedPalette()
{ {
if (function_exists('imagewebp')) { if (function_exists('imagewebp')) {
@@ -75,17 +75,18 @@ class EncoderTest extends TestCase
} }
} }
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessAvifGd() public function testProcessAvifGd()
{ {
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); if (function_exists('imageavif')) {
$encoder = new GdEncoder; $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$image = Mockery::mock('\Intervention\Image\Image'); $encoder = new GdEncoder;
$img = $encoder->process($image, 'avif', 90); $image = Mockery::mock('\Intervention\Image\Image');
$this->assertInstanceOf('Intervention\Image\Image', $img); $image->shouldReceive('getCore')->once()->andReturn($core);
$image->shouldReceive('setEncoded')->once()->andReturn($image);
$img = $encoder->process($image, 'avif', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('image/avif; charset=binary', $this->getMime($encoder->result));
}
} }
/** /**