mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 22:12:51 +02:00
@@ -91,6 +91,13 @@ abstract class AbstractEncoder
|
||||
*/
|
||||
abstract protected function processAvif();
|
||||
|
||||
/**
|
||||
* Processes and returns image as Heic encoded string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function processHeic();
|
||||
|
||||
/**
|
||||
* Process a given image
|
||||
*
|
||||
@@ -182,6 +189,11 @@ abstract class AbstractEncoder
|
||||
case 'image/avif':
|
||||
$this->result = $this->processAvif();
|
||||
break;
|
||||
|
||||
case 'heic':
|
||||
case 'image/heic':
|
||||
$this->result = $this->processHeic();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(
|
||||
|
@@ -57,6 +57,11 @@ class Encoder extends \Intervention\Image\AbstractEncoder
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and returns encoded image as WEBP string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processWebp()
|
||||
{
|
||||
if ( ! function_exists('imagewebp')) {
|
||||
@@ -146,4 +151,16 @@ class Encoder extends \Intervention\Image\AbstractEncoder
|
||||
"AVIF format is not supported by Gd Driver."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and returns encoded image as HEIC string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processHeic()
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
"HEIC format is not supported by Gd Driver."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -183,6 +183,11 @@ class Encoder extends AbstractEncoder
|
||||
return $imagick->getImagesBlob();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and returns encoded image as AVIF string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processAvif()
|
||||
{
|
||||
if ( ! \Imagick::queryFormats('AVIF')) {
|
||||
@@ -204,4 +209,31 @@ class Encoder extends AbstractEncoder
|
||||
|
||||
return $imagick->getImagesBlob();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and returns encoded image as HEIC string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processHeic()
|
||||
{
|
||||
if ( ! \Imagick::queryFormats('HEIC')) {
|
||||
throw new NotSupportedException(
|
||||
"HEIC format is not supported by Imagick installation."
|
||||
);
|
||||
}
|
||||
|
||||
$format = 'heic';
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
@@ -88,6 +88,18 @@ class EncoderTest extends TestCase
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
||||
*/
|
||||
public function testProcessHeicGd()
|
||||
{
|
||||
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||
$encoder = new GdEncoder;
|
||||
$image = Mockery::mock('\Intervention\Image\Image');
|
||||
$img = $encoder->process($image, 'heic', 90);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
||||
*/
|
||||
@@ -219,6 +231,16 @@ class EncoderTest extends TestCase
|
||||
$img = $encoder->process($image, 'avif', 90);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Intervention\Image\Exception\NotSupportedException
|
||||
*/
|
||||
public function testProcessHeicImagick()
|
||||
{
|
||||
$encoder = new ImagickEncoder;
|
||||
$image = Mockery::mock('\Intervention\Image\Image');
|
||||
$img = $encoder->process($image, 'heic', 90);
|
||||
}
|
||||
|
||||
public function testProcessTiffImagick()
|
||||
{
|
||||
$core = $this->getImagickMock('tiff');
|
||||
|
Reference in New Issue
Block a user