Skip to content

Commit fe602ae

Browse files
committed
Support JXL in Imagick driver
1 parent b6b6315 commit fe602ae

File tree

10 files changed

+79
-4
lines changed

10 files changed

+79
-4
lines changed

src/Imagick/Image.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,22 @@ private function applyImageOptions(\Imagick $image, array $options, $path)
830830
$image->setOption('webp:lossless', $options['webp_lossless']);
831831
}
832832
break;
833+
case 'jxl':
834+
if (!isset($options[$format . '_quality'])) {
835+
if (isset($options['quality'])) {
836+
$options[$format . '_quality'] = $options['quality'];
837+
}
838+
}
839+
if (isset($options[$format . '_quality'])) {
840+
$options[$format . '_quality'] = max(9, min(99, $options[$format . '_quality']));
841+
$image->setimagecompressionquality($options[$format . '_quality']);
842+
$image->setcompressionquality($options[$format . '_quality']);
843+
}
844+
if (!empty($options[$format . '_lossless'])) {
845+
$image->setimagecompressionquality(100);
846+
$image->setcompressionquality(100);
847+
}
848+
break;
833849
}
834850
if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) {
835851
if (empty($options['resampling-filter'])) {
@@ -935,6 +951,7 @@ private function getMimeType($format)
935951
static $mimeTypes = array(
936952
'jpeg' => 'image/jpeg',
937953
'jpg' => 'image/jpeg',
954+
'jxl' => 'image/jxl',
938955
'gif' => 'image/gif',
939956
'png' => 'image/png',
940957
'wbmp' => 'image/vnd.wap.wbmp',

tests/fixtures/jxl-image.jxl

32 Bytes
Binary file not shown.

tests/tests/Gd/ImageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ 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 === 'jxl') {
197+
$this->markTestSkipped('GD does not support ' . strtoupper($format));
198+
}
196199

197200
return parent::testSaveCompressionQuality($format, $smallSizeOptions, $bigSizeOptions);
198201
}

tests/tests/Gd/ImagineTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function testShouldOpenAWebPImage()
4747
return parent::testShouldOpenAWebPImage();
4848
}
4949

50+
/**
51+
* {@inheritdoc}
52+
*
53+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
54+
*/
55+
public function testShouldOpenAJxlImage()
56+
{
57+
$this->markTestSkipped('GD does not support JXL');
58+
}
59+
5060
/**
5161
* {@inheritdoc}
5262
*

tests/tests/Gmagick/ImageTest.php

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

152152
return parent::testSaveCompressionQuality($format, $smallSizeOptions, $bigSizeOptions);

tests/tests/Gmagick/ImagineTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ public function testShouldOpenAWebPImage()
6060
return parent::testShouldOpenAWebPImage();
6161
}
6262

63+
/**
64+
* {@inheritdoc}
65+
*
66+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
67+
*/
68+
public function testShouldOpenAJxlImage()
69+
{
70+
$gmagick = new \Gmagick();
71+
if (!in_array('JXL', $gmagick->queryformats('JXL'), true)) {
72+
$this->markTestSkipped('Gmagick JXL support is not enabled');
73+
}
74+
75+
return parent::testShouldOpenAJxlImage();
76+
}
77+
6378
/**
6479
* {@inheritdoc}
6580
*

tests/tests/Image/AbstractImageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,8 @@ public function imageCompressionQualityProvider()
981981
array('jpg', array('jpeg_quality' => 0), array('jpeg_quality' => 100)),
982982
array('png', array('png_compression_level' => 9), array('png_compression_level' => 0)),
983983
array('webp', array('webp_quality' => 0), array('webp_quality' => 100)),
984+
array('jxl', array('jxl_quality' => 0), array('jxl_quality' => 100)),
985+
array('jxl', array('jxl_quality' => 0), array('jxl_lossless' => true)),
984986
);
985987
}
986988

tests/tests/Image/AbstractImagineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ public function testShouldOpenAWebPImage()
6161
$this->assertEquals(realpath($source), $metadata['filepath']);
6262
}
6363

64+
public function testShouldOpenAJxlImage()
65+
{
66+
$source = IMAGINE_TEST_FIXTURESFOLDER . '/jxl-image.jxl';
67+
$factory = $this->getImagine();
68+
$image = $factory->open($source);
69+
$size = $image->getSize();
70+
$this->assertInstanceOf('Imagine\Image\ImageInterface', $image);
71+
$this->assertEquals(100, $size->getWidth());
72+
$this->assertEquals(100, $size->getHeight());
73+
$metadata = $image->metadata();
74+
$this->assertEquals($source, $metadata['uri']);
75+
$this->assertEquals(realpath($source), $metadata['filepath']);
76+
}
77+
6478
public function testShouldOpenAnSplFileResource()
6579
{
6680
$source = IMAGINE_TEST_FIXTURESFOLDER . '/google.png';

tests/tests/Imagick/ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ public function testOptimize()
172172
*/
173173
public function testSaveCompressionQuality($format, array $smallSizeOptions, array $bigSizeOptions)
174174
{
175-
if ($format === 'webp' && !in_array('WEBP', \Imagick::queryFormats('WEBP'), true)) {
176-
$this->markTestSkipped('Imagick WebP support is not enabled');
175+
if (in_array($format, array('webp', 'jxl'), true) && !in_array(strtoupper($format), \Imagick::queryFormats(strtoupper($format)), true)) {
176+
$this->markTestSkipped('Imagick ' . $format . ' support is not enabled');
177177
}
178178

179179
return parent::testSaveCompressionQuality($format, $smallSizeOptions, $bigSizeOptions);

tests/tests/Imagick/ImagineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function testShouldOpenAWebPImage()
4747
return parent::testShouldOpenAWebPImage();
4848
}
4949

50+
/**
51+
* {@inheritdoc}
52+
*
53+
* @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage()
54+
*/
55+
public function testShouldOpenAJxlImage()
56+
{
57+
if (!in_array('JXL', \Imagick::queryFormats('JXL'), true)) {
58+
$this->markTestSkipped('Imagick JXL support is not enabled');
59+
}
60+
61+
return parent::testShouldOpenAJxlImage();
62+
}
63+
5064
/**
5165
* {@inheritdoc}
5266
*

0 commit comments

Comments
 (0)