mirror of
https://github.com/Intervention/image.git
synced 2025-08-15 18:34:03 +02:00
Merge pull request #1056 from freshleafmedia/feature/avif-support
AVIF Support
This commit is contained in:
@@ -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
|
|||||||
case 'image/x-webp':
|
case 'image/x-webp':
|
||||||
$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(
|
||||||
|
@@ -122,4 +122,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."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,6 +76,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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
||||||
*/
|
*/
|
||||||
@@ -195,6 +207,16 @@ class EncoderTest extends TestCase
|
|||||||
$img = $encoder->process($image, 'webp', 90);
|
$img = $encoder->process($image, 'webp', 90);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
||||||
|
*/
|
||||||
|
public function testProcessAvifImagick()
|
||||||
|
{
|
||||||
|
$encoder = new ImagickEncoder;
|
||||||
|
$image = Mockery::mock('\Intervention\Image\Image');
|
||||||
|
$img = $encoder->process($image, 'avif', 90);
|
||||||
|
}
|
||||||
|
|
||||||
public function testProcessTiffImagick()
|
public function testProcessTiffImagick()
|
||||||
{
|
{
|
||||||
$core = $this->getImagickMock('tiff');
|
$core = $this->getImagickMock('tiff');
|
||||||
|
Reference in New Issue
Block a user