diff --git a/config/mediable.php b/config/mediable.php index 4f14ee9..0aa62a4 100644 --- a/config/mediable.php +++ b/config/mediable.php @@ -94,12 +94,14 @@ 'image/jpeg', 'image/png', 'image/gif', + 'image/heic', ], 'extensions' => [ 'jpg', 'jpeg', 'png', 'gif', + 'heic', ] ], Plank\Mediable\Media::TYPE_IMAGE_VECTOR => [ diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index b69afce..344df6b 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -9,27 +9,30 @@ class ImageManipulation { + public const FORMAT_BMP = 'bmp'; + public const FORMAT_GIF = 'gif'; + public const FORMAT_HEIC = 'heic'; public const FORMAT_JPG = 'jpg'; public const FORMAT_PNG = 'png'; - public const FORMAT_GIF = 'gif'; public const FORMAT_TIFF = 'tif'; - public const FORMAT_BMP = 'bmp'; public const FORMAT_WEBP = 'webp'; public const VALID_IMAGE_FORMATS = [ + self::FORMAT_BMP, + self::FORMAT_GIF, + self::FORMAT_HEIC, self::FORMAT_JPG, self::FORMAT_PNG, - self::FORMAT_GIF, self::FORMAT_TIFF, - self::FORMAT_BMP ]; public const MIME_TYPE_MAP = [ + self::FORMAT_BMP => 'image/bmp', + self::FORMAT_GIF => 'image/gif', + self::FORMAT_HEIC => 'image/heic', self::FORMAT_JPG => 'image/jpeg', self::FORMAT_PNG => 'image/png', - self::FORMAT_GIF => 'image/gif', self::FORMAT_TIFF => 'image/tiff', - self::FORMAT_BMP => 'image/bmp', self::FORMAT_WEBP => 'image/webp' ]; @@ -182,6 +185,13 @@ public function outputWebpFormat(): self return $this; } + public function outputHeicFormat(): self + { + $this->setOutputFormat(self::FORMAT_HEIC); + + return $this; + } + /** * @return callable */ diff --git a/src/ImageManipulator.php b/src/ImageManipulator.php index bf07e19..2f11096 100644 --- a/src/ImageManipulator.php +++ b/src/ImageManipulator.php @@ -411,6 +411,7 @@ private function imageToStream( ImageManipulation::FORMAT_GIF => $image->toGif(), ImageManipulation::FORMAT_WEBP => $image->toBitmap(), ImageManipulation::FORMAT_TIFF => $image->toTiff($outputQuality), + ImageManipulation::FORMAT_HEIC => $image->toHeic($outputQuality), default => throw ImageManipulationException::unknownOutputFormat(), }; return Utils::streamFor($formatted->toFilePointer()); diff --git a/tests/Integration/ImageManipulationTest.php b/tests/Integration/ImageManipulationTest.php index c175750..2e6f7f3 100644 --- a/tests/Integration/ImageManipulationTest.php +++ b/tests/Integration/ImageManipulationTest.php @@ -46,6 +46,8 @@ public function test_can_get_set_output_format(): void $this->assertEquals('webp', $manipulation->getOutputFormat()); $manipulation->outputJpegFormat(); $this->assertEquals('jpg', $manipulation->getOutputFormat()); + $manipulation->outputHeicFormat(); + $this->assertEquals('heic', $manipulation->getOutputFormat()); } public function test_can_get_set_before_save_callback(): void diff --git a/tests/TestCase.php b/tests/TestCase.php index 9226c4b..ca017fc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,6 @@ use Faker\Factory; use GuzzleHttp\Psr7\Utils; use Illuminate\Filesystem\Filesystem; -use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\ImageManager; use Orchestra\Testbench\TestCase as BaseTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -105,8 +104,18 @@ protected function getEnvironmentSetUp($app) $app['config']->set('mediable.image_optimization.enabled', false); - if (class_exists(Driver::class)) { - $app->instance(ImageManager::class, new ImageManager(new Driver())); + if (class_exists(\Intervention\Image\Drivers\Imagick\Driver::class) + && class_exists('Imagick') + ) { + $app->instance( + ImageManager::class, + new ImageManager(new \Intervention\Image\Drivers\Imagick\Driver()) + ); + } elseif (class_exists(\Intervention\Image\Drivers\Gd\Driver::class)) { + $app->instance( + ImageManager::class, + new ImageManager(new \Intervention\Image\Drivers\Gd\Driver()) + ); } }