Skip to content

Commit 2360344

Browse files
authored
Merge pull request #765 from ausi/fix/imagick-jxl
Support JXL in Imagick driver
2 parents a66bee6 + c1cb59c commit 2360344

File tree

10 files changed

+76
-3
lines changed

10 files changed

+76
-3
lines changed

src/Imagick/Image.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,23 @@ private function applyImageOptions(\Imagick $image, array $options, $path)
848848
}
849849
}
850850
break;
851+
case 'jxl':
852+
if (!empty($options[$format . '_lossless'])) {
853+
$image->setimagecompressionquality(100);
854+
$image->setcompressionquality(100);
855+
} else {
856+
if (!isset($options[$format . '_quality'])) {
857+
if (isset($options['quality'])) {
858+
$options[$format . '_quality'] = $options['quality'];
859+
}
860+
}
861+
if (isset($options[$format . '_quality'])) {
862+
$options[$format . '_quality'] = max(9, min(99, $options[$format . '_quality']));
863+
$image->setimagecompressionquality($options[$format . '_quality']);
864+
$image->setcompressionquality($options[$format . '_quality']);
865+
}
866+
}
867+
break;
851868
}
852869
if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) {
853870
if (empty($options['resampling-filter'])) {
@@ -953,6 +970,7 @@ private function getMimeType($format)
953970
static $mimeTypes = array(
954971
'jpeg' => 'image/jpeg',
955972
'jpg' => 'image/jpeg',
973+
'jxl' => 'image/jxl',
956974
'gif' => 'image/gif',
957975
'png' => 'image/png',
958976
'wbmp' => 'image/vnd.wap.wbmp',

tests/fixtures/jxl-image.jxl

32 Bytes
Binary file not shown.

tests/tests/Gd/ImageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function testSaveCompressionQuality($format, array $smallSizeOptions, arr
193193
if ($format === 'webp' && !function_exists('imagewebp')) {
194194
$this->markTestSkipped('GD webp support is not enabled');
195195
}
196-
if ($format === 'avif' || $format === 'heic') {
196+
if ($format === 'avif' || $format === 'heic' || $format === 'jxl') {
197197
$this->markTestSkipped('GD does not support ' . strtoupper($format));
198198
}
199199

tests/tests/Gd/ImagineTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public function testShouldOpenAHeicImage()
6767
$this->markTestSkipped('GD does not support HEIC');
6868
}
6969

70+
/**
71+
* {@inheritdoc}
72+
*
73+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
74+
*/
75+
public function testShouldOpenAJxlImage()
76+
{
77+
$this->markTestSkipped('GD does not support JXL');
78+
}
79+
7080
/**
7181
* {@inheritdoc}
7282
*

tests/tests/Gmagick/ImageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function pasteWithAlphaProvider()
145145
public function testSaveCompressionQuality($format, array $smallSizeOptions, array $bigSizeOptions)
146146
{
147147
$gmagick = new \Gmagick();
148-
if (in_array($format, array('webp', 'avif', 'heic'), true) && !in_array(strtoupper($format), $gmagick->queryformats(strtoupper($format)), true)) {
148+
if (in_array($format, array('webp', 'avif', 'heic', 'jxl'), true) && !in_array(strtoupper($format), $gmagick->queryformats(strtoupper($format)), true)) {
149149
$this->markTestSkipped('Gmagick ' . $format . ' support is not enabled');
150150
}
151151

tests/tests/Gmagick/ImagineTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ public function testShouldOpenAHeicImage()
9090
return parent::testShouldOpenAHeicImage();
9191
}
9292

93+
/**
94+
* {@inheritdoc}
95+
*
96+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
97+
*/
98+
public function testShouldOpenAJxlImage()
99+
{
100+
$gmagick = new \Gmagick();
101+
if (!in_array('JXL', $gmagick->queryformats('JXL'), true)) {
102+
$this->markTestSkipped('Gmagick JXL support is not enabled');
103+
}
104+
105+
return parent::testShouldOpenAJxlImage();
106+
}
107+
93108
/**
94109
* {@inheritdoc}
95110
*

tests/tests/Image/AbstractImageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ public function imageCompressionQualityProvider()
10061006
array('avif', array('avif_quality' => 0), array('avif_lossless' => true)),
10071007
array('heic', array('heic_quality' => 0), array('heic_quality' => 100)),
10081008
array('heic', array('heic_quality' => 0), array('heic_lossless' => true)),
1009+
array('jxl', array('jxl_quality' => 0), array('jxl_quality' => 100)),
1010+
array('jxl', array('jxl_quality' => 0), array('jxl_lossless' => true)),
10091011
);
10101012
}
10111013

tests/tests/Image/AbstractImagineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public function testShouldOpenAHeicImage()
8989
$this->assertEquals(realpath($source), $metadata['filepath']);
9090
}
9191

92+
public function testShouldOpenAJxlImage()
93+
{
94+
$source = IMAGINE_TEST_FIXTURESFOLDER . '/jxl-image.jxl';
95+
$factory = $this->getImagine();
96+
$image = $factory->open($source);
97+
$size = $image->getSize();
98+
$this->assertInstanceOf('Imagine\Image\ImageInterface', $image);
99+
$this->assertEquals(100, $size->getWidth());
100+
$this->assertEquals(100, $size->getHeight());
101+
$metadata = $image->metadata();
102+
$this->assertEquals($source, $metadata['uri']);
103+
$this->assertEquals(realpath($source), $metadata['filepath']);
104+
}
105+
92106
public function testShouldOpenAnSplFileResource()
93107
{
94108
$source = IMAGINE_TEST_FIXTURESFOLDER . '/google.png';

tests/tests/Imagick/ImageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function testOptimize()
172172
*/
173173
public function testSaveCompressionQuality($format, array $smallSizeOptions, array $bigSizeOptions)
174174
{
175-
if (in_array($format, array('webp', 'avif', 'heic'), true) && !in_array(strtoupper($format), \Imagick::queryFormats(strtoupper($format)), true)) {
175+
if (in_array($format, array('webp', 'avif', 'heic', 'jxl'), true) && !in_array(strtoupper($format), \Imagick::queryFormats(strtoupper($format)), true)) {
176176
$this->markTestSkipped('Imagick ' . $format . ' support is not enabled');
177177
}
178178

tests/tests/Imagick/ImagineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ public function testShouldOpenAHeicImage()
7575
return parent::testShouldOpenAHeicImage();
7676
}
7777

78+
/**
79+
* {@inheritdoc}
80+
*
81+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
82+
*/
83+
public function testShouldOpenAJxlImage()
84+
{
85+
if (!in_array('JXL', \Imagick::queryFormats('JXL'), true)) {
86+
$this->markTestSkipped('Imagick JXL support is not enabled');
87+
}
88+
89+
return parent::testShouldOpenAJxlImage();
90+
}
91+
7892
/**
7993
* {@inheritdoc}
8094
*

0 commit comments

Comments
 (0)