mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 05:52:47 +02:00
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user