Skip to content

Commit ebf9bb0

Browse files
authored
Add support for webp_lossless to GD and GMagick (#858)
1 parent 922e032 commit ebf9bb0

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Gd/Image.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,9 @@ private function finalizeOptions(Format $format, array $options)
730730
$options['webp_quality'] = $options['quality'];
731731
}
732732
}
733-
if (isset($options['webp_quality'])) {
733+
if (!empty($options['webp_lossless'])) {
734+
$result[] = defined('IMG_WEBP_LOSSLESS') ? IMG_WEBP_LOSSLESS : 100;
735+
} elseif (isset($options['webp_quality'])) {
734736
if ($options['webp_quality'] < 0 || $options['webp_quality'] > 100) {
735737
throw new InvalidArgumentException('webp_quality option should be an integer from 0 to 100');
736738
}

src/Gmagick/Image.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ private function applyImageOptions(\Gmagick $image, array $options, $path)
368368
if (isset($options['webp_quality'])) {
369369
$image->setCompressionQuality($options['webp_quality']);
370370
}
371+
if (isset($options['webp_lossless'])) {
372+
if (method_exists($image, 'setimageoption')) {
373+
$image->setimageoption('webp', 'lossless', $options['webp_lossless'] ? 'true' : 'false');
374+
} elseif ($options['webp_lossless']) {
375+
$image->setCompressionQuality(100);
376+
}
377+
}
371378
break;
372379
}
373380
if (isset($options['resolution-units']) && isset($options['resolution-x']) && isset($options['resolution-y'])) {

tests/tests/Image/AbstractImageTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ public function imageCompressionQualityProvider()
11271127
array(Format::ID_JPEG, array('jpeg_quality' => 0), array('jpeg_quality' => 100)),
11281128
array(Format::ID_PNG, array('png_compression_level' => 9), array('png_compression_level' => 0)),
11291129
array(Format::ID_WEBP, array('webp_quality' => 0), array('webp_quality' => 100)),
1130+
array(Format::ID_WEBP, array('webp_quality' => 0), array('webp_lossless' => true)),
11301131
array(Format::ID_AVIF, array('avif_quality' => 0), array('avif_quality' => 100)),
11311132
array(Format::ID_AVIF, array('avif_quality' => 0), array('avif_lossless' => true)),
11321133
array(Format::ID_HEIC, array('heic_quality' => 0), array('heic_quality' => 100)),

0 commit comments

Comments
 (0)