1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 21:42:53 +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()
{
throw new NotSupportedException(
"AVIF format is not supported by Gd Driver."
);
if ( ! function_exists('imageavif')) {
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));
}
}
public function testProcessWebpGdWithUnSupportedPalette()
{
if (function_exists('imagewebp')) {
@@ -75,17 +75,18 @@ class EncoderTest extends TestCase
}
}
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessAvifGd()
{
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$img = $encoder->process($image, 'avif', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
if (function_exists('imageavif')) {
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$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));
}
}
/**