Skip to content

Commit b094b69

Browse files
committed
add support for HEIC
1 parent 0adf971 commit b094b69

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

config/mediable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@
9494
'image/jpeg',
9595
'image/png',
9696
'image/gif',
97+
'image/heic',
9798
],
9899
'extensions' => [
99100
'jpg',
100101
'jpeg',
101102
'png',
102103
'gif',
104+
'heic',
103105
]
104106
],
105107
Plank\Mediable\Media::TYPE_IMAGE_VECTOR => [

src/ImageManipulation.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@
99

1010
class ImageManipulation
1111
{
12+
public const FORMAT_BMP = 'bmp';
13+
public const FORMAT_GIF = 'gif';
14+
public const FORMAT_HEIC = 'heic';
1215
public const FORMAT_JPG = 'jpg';
1316
public const FORMAT_PNG = 'png';
14-
public const FORMAT_GIF = 'gif';
1517
public const FORMAT_TIFF = 'tif';
16-
public const FORMAT_BMP = 'bmp';
1718
public const FORMAT_WEBP = 'webp';
1819

1920
public const VALID_IMAGE_FORMATS = [
21+
self::FORMAT_BMP,
22+
self::FORMAT_GIF,
23+
self::FORMAT_HEIC,
2024
self::FORMAT_JPG,
2125
self::FORMAT_PNG,
22-
self::FORMAT_GIF,
2326
self::FORMAT_TIFF,
24-
self::FORMAT_BMP
2527
];
2628

2729
public const MIME_TYPE_MAP = [
30+
self::FORMAT_BMP => 'image/bmp',
31+
self::FORMAT_GIF => 'image/gif',
32+
self::FORMAT_HEIC => 'image/heic',
2833
self::FORMAT_JPG => 'image/jpeg',
2934
self::FORMAT_PNG => 'image/png',
30-
self::FORMAT_GIF => 'image/gif',
3135
self::FORMAT_TIFF => 'image/tiff',
32-
self::FORMAT_BMP => 'image/bmp',
3336
self::FORMAT_WEBP => 'image/webp'
3437
];
3538

@@ -182,6 +185,13 @@ public function outputWebpFormat(): self
182185
return $this;
183186
}
184187

188+
public function outputHeicFormat(): self
189+
{
190+
$this->setOutputFormat(self::FORMAT_HEIC);
191+
192+
return $this;
193+
}
194+
185195
/**
186196
* @return callable
187197
*/

src/ImageManipulator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ private function imageToStream(
411411
ImageManipulation::FORMAT_GIF => $image->toGif(),
412412
ImageManipulation::FORMAT_WEBP => $image->toBitmap(),
413413
ImageManipulation::FORMAT_TIFF => $image->toTiff($outputQuality),
414+
ImageManipulation::FORMAT_HEIC => $image->toHeic($outputQuality),
414415
default => throw ImageManipulationException::unknownOutputFormat(),
415416
};
416417
return Utils::streamFor($formatted->toFilePointer());

tests/Integration/ImageManipulationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function test_can_get_set_output_format(): void
4646
$this->assertEquals('webp', $manipulation->getOutputFormat());
4747
$manipulation->outputJpegFormat();
4848
$this->assertEquals('jpg', $manipulation->getOutputFormat());
49+
$manipulation->outputHeicFormat();
50+
$this->assertEquals('heic', $manipulation->getOutputFormat());
4951
}
5052

5153
public function test_can_get_set_before_save_callback(): void

tests/TestCase.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Faker\Factory;
77
use GuzzleHttp\Psr7\Utils;
88
use Illuminate\Filesystem\Filesystem;
9-
use Intervention\Image\Drivers\Gd\Driver;
109
use Intervention\Image\ImageManager;
1110
use Orchestra\Testbench\TestCase as BaseTestCase;
1211
use PHPUnit\Framework\MockObject\MockObject;
@@ -105,8 +104,18 @@ protected function getEnvironmentSetUp($app)
105104

106105
$app['config']->set('mediable.image_optimization.enabled', false);
107106

108-
if (class_exists(Driver::class)) {
109-
$app->instance(ImageManager::class, new ImageManager(new Driver()));
107+
if (class_exists(\Intervention\Image\Drivers\Imagick\Driver::class)
108+
&& class_exists('Imagick')
109+
) {
110+
$app->instance(
111+
ImageManager::class,
112+
new ImageManager(new \Intervention\Image\Drivers\Imagick\Driver())
113+
);
114+
} elseif (class_exists(\Intervention\Image\Drivers\Gd\Driver::class)) {
115+
$app->instance(
116+
ImageManager::class,
117+
new ImageManager(new \Intervention\Image\Drivers\Gd\Driver())
118+
);
110119
}
111120
}
112121

0 commit comments

Comments
 (0)