diff --git a/src/Imagick/Image.php b/src/Imagick/Image.php index 25fa4fa2..c552280e 100644 --- a/src/Imagick/Image.php +++ b/src/Imagick/Image.php @@ -848,6 +848,22 @@ private function applyImageOptions(\Imagick $image, array $options, $path) } } break; + case 'jxl': + if (!isset($options[$format . '_quality'])) { + if (isset($options['quality'])) { + $options[$format . '_quality'] = $options['quality']; + } + } + if (isset($options[$format . '_quality'])) { + $options[$format . '_quality'] = max(9, min(99, $options[$format . '_quality'])); + $image->setimagecompressionquality($options[$format . '_quality']); + $image->setcompressionquality($options[$format . '_quality']); + } + if (!empty($options[$format . '_lossless'])) { + $image->setimagecompressionquality(100); + $image->setcompressionquality(100); + } + break; } if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) { if (empty($options['resampling-filter'])) { @@ -953,6 +969,7 @@ private function getMimeType($format) static $mimeTypes = array( 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', + 'jxl' => 'image/jxl', 'gif' => 'image/gif', 'png' => 'image/png', 'wbmp' => 'image/vnd.wap.wbmp', diff --git a/tests/fixtures/jxl-image.jxl b/tests/fixtures/jxl-image.jxl new file mode 100644 index 00000000..dd86e685 Binary files /dev/null and b/tests/fixtures/jxl-image.jxl differ diff --git a/tests/tests/Gd/ImageTest.php b/tests/tests/Gd/ImageTest.php index e605c3c3..1031db8e 100644 --- a/tests/tests/Gd/ImageTest.php +++ b/tests/tests/Gd/ImageTest.php @@ -193,7 +193,7 @@ public function testSaveCompressionQuality($format, array $smallSizeOptions, arr if ($format === 'webp' && !function_exists('imagewebp')) { $this->markTestSkipped('GD webp support is not enabled'); } - if ($format === 'avif' || $format === 'heic') { + if ($format === 'avif' || $format === 'heic' || $format === 'jxl') { $this->markTestSkipped('GD does not support ' . strtoupper($format)); } diff --git a/tests/tests/Gd/ImagineTest.php b/tests/tests/Gd/ImagineTest.php index c9116093..927f4387 100644 --- a/tests/tests/Gd/ImagineTest.php +++ b/tests/tests/Gd/ImagineTest.php @@ -67,6 +67,16 @@ public function testShouldOpenAHeicImage() $this->markTestSkipped('GD does not support HEIC'); } + /** + * {@inheritdoc} + * + * @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage() + */ + public function testShouldOpenAJxlImage() + { + $this->markTestSkipped('GD does not support JXL'); + } + /** * {@inheritdoc} * diff --git a/tests/tests/Gmagick/ImageTest.php b/tests/tests/Gmagick/ImageTest.php index 9c227794..be351983 100644 --- a/tests/tests/Gmagick/ImageTest.php +++ b/tests/tests/Gmagick/ImageTest.php @@ -145,7 +145,7 @@ public function pasteWithAlphaProvider() public function testSaveCompressionQuality($format, array $smallSizeOptions, array $bigSizeOptions) { $gmagick = new \Gmagick(); - if (in_array($format, array('webp', 'avif', 'heic'), true) && !in_array(strtoupper($format), $gmagick->queryformats(strtoupper($format)), true)) { + if (in_array($format, array('webp', 'avif', 'heic', 'jxl'), true) && !in_array(strtoupper($format), $gmagick->queryformats(strtoupper($format)), true)) { $this->markTestSkipped('Gmagick ' . $format . ' support is not enabled'); } diff --git a/tests/tests/Gmagick/ImagineTest.php b/tests/tests/Gmagick/ImagineTest.php index 9c162891..35a6121f 100644 --- a/tests/tests/Gmagick/ImagineTest.php +++ b/tests/tests/Gmagick/ImagineTest.php @@ -90,6 +90,21 @@ public function testShouldOpenAHeicImage() return parent::testShouldOpenAHeicImage(); } + /** + * {@inheritdoc} + * + * @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage() + */ + public function testShouldOpenAJxlImage() + { + $gmagick = new \Gmagick(); + if (!in_array('JXL', $gmagick->queryformats('JXL'), true)) { + $this->markTestSkipped('Gmagick JXL support is not enabled'); + } + + return parent::testShouldOpenAJxlImage(); + } + /** * {@inheritdoc} * diff --git a/tests/tests/Image/AbstractImageTest.php b/tests/tests/Image/AbstractImageTest.php index 815cf346..e6a96255 100644 --- a/tests/tests/Image/AbstractImageTest.php +++ b/tests/tests/Image/AbstractImageTest.php @@ -1006,6 +1006,8 @@ public function imageCompressionQualityProvider() array('avif', array('avif_quality' => 0), array('avif_lossless' => true)), array('heic', array('heic_quality' => 0), array('heic_quality' => 100)), array('heic', array('heic_quality' => 0), array('heic_lossless' => true)), + array('jxl', array('jxl_quality' => 0), array('jxl_quality' => 100)), + array('jxl', array('jxl_quality' => 0), array('jxl_lossless' => true)), ); } diff --git a/tests/tests/Image/AbstractImagineTest.php b/tests/tests/Image/AbstractImagineTest.php index 2329de78..3bdc5092 100644 --- a/tests/tests/Image/AbstractImagineTest.php +++ b/tests/tests/Image/AbstractImagineTest.php @@ -89,6 +89,20 @@ public function testShouldOpenAHeicImage() $this->assertEquals(realpath($source), $metadata['filepath']); } + public function testShouldOpenAJxlImage() + { + $source = IMAGINE_TEST_FIXTURESFOLDER . '/jxl-image.jxl'; + $factory = $this->getImagine(); + $image = $factory->open($source); + $size = $image->getSize(); + $this->assertInstanceOf('Imagine\Image\ImageInterface', $image); + $this->assertEquals(100, $size->getWidth()); + $this->assertEquals(100, $size->getHeight()); + $metadata = $image->metadata(); + $this->assertEquals($source, $metadata['uri']); + $this->assertEquals(realpath($source), $metadata['filepath']); + } + public function testShouldOpenAnSplFileResource() { $source = IMAGINE_TEST_FIXTURESFOLDER . '/google.png'; diff --git a/tests/tests/Imagick/ImageTest.php b/tests/tests/Imagick/ImageTest.php index 8075c9d1..97e32370 100644 --- a/tests/tests/Imagick/ImageTest.php +++ b/tests/tests/Imagick/ImageTest.php @@ -172,7 +172,7 @@ public function testOptimize() */ public function testSaveCompressionQuality($format, array $smallSizeOptions, array $bigSizeOptions) { - if (in_array($format, array('webp', 'avif', 'heic'), true) && !in_array(strtoupper($format), \Imagick::queryFormats(strtoupper($format)), true)) { + if (in_array($format, array('webp', 'avif', 'heic', 'jxl'), true) && !in_array(strtoupper($format), \Imagick::queryFormats(strtoupper($format)), true)) { $this->markTestSkipped('Imagick ' . $format . ' support is not enabled'); } diff --git a/tests/tests/Imagick/ImagineTest.php b/tests/tests/Imagick/ImagineTest.php index 7bd6509a..70959cf5 100644 --- a/tests/tests/Imagick/ImagineTest.php +++ b/tests/tests/Imagick/ImagineTest.php @@ -75,6 +75,20 @@ public function testShouldOpenAHeicImage() return parent::testShouldOpenAHeicImage(); } + /** + * {@inheritdoc} + * + * @see \Imagine\Test\Image\AbstractImagineTest::testShouldOpenAJxlImage() + */ + public function testShouldOpenAJxlImage() + { + if (!in_array('JXL', \Imagick::queryFormats('JXL'), true)) { + $this->markTestSkipped('Imagick JXL support is not enabled'); + } + + return parent::testShouldOpenAJxlImage(); + } + /** * {@inheritdoc} *