1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-24 14:32:52 +02:00

Merge pull request #1104 from it-can/master

Add HEIC support
This commit is contained in:
Oliver Vogel
2021-08-11 16:40:26 +02:00
committed by GitHub
4 changed files with 83 additions and 0 deletions

View File

@@ -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(

View File

@@ -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."
);
}
}

View File

@@ -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();
}
}

View File

@@ -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');