1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 12:41:23 +02:00

Add HEIC support

This commit is contained in:
Michiel Vugteveen
2021-07-23 20:45:18 +02:00
parent 0925f10b25
commit 3ddcc2d55d
4 changed files with 62 additions and 0 deletions

View File

@@ -91,6 +91,13 @@ abstract class AbstractEncoder
*/ */
abstract protected function processAvif(); abstract protected function processAvif();
/**
* Processes and returns image as Heic encoded string
*
* @return string
*/
abstract protected function processHeic();
/** /**
* Process a given image * Process a given image
* *

View File

@@ -144,6 +144,17 @@ class Encoder extends \Intervention\Image\AbstractEncoder
{ {
throw new NotSupportedException( throw new NotSupportedException(
"AVIF format is not supported by Gd Driver." "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."
); );
} }
} }

View File

@@ -204,4 +204,26 @@ class Encoder extends AbstractEncoder
return $imagick->getImagesBlob(); return $imagick->getImagesBlob();
} }
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();
}
} }

View File

@@ -88,6 +88,18 @@ class EncoderTest extends TestCase
$this->assertInstanceOf('Intervention\Image\Image', $img); $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 * @expectedException \Intervention\Image\Exception\NotSupportedException
*/ */
@@ -219,6 +231,16 @@ class EncoderTest extends TestCase
$img = $encoder->process($image, 'avif', 90); $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() public function testProcessTiffImagick()
{ {
$core = $this->getImagickMock('tiff'); $core = $this->getImagickMock('tiff');