From bc09f0d42fba594b5a88a530d86cba6a11ebfd84 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Tue, 19 Dec 2023 16:52:15 +0100 Subject: [PATCH] Set lossless quality for GD WebpEncoder A value of 101 is actually specified for lossless coding with GD. However, since Imagick expects 100 for lossless in WebP format, I adjust this for both drivers. --- src/Drivers/Gd/Encoders/WebpEncoder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Drivers/Gd/Encoders/WebpEncoder.php b/src/Drivers/Gd/Encoders/WebpEncoder.php index 23939a3c..1a590dbe 100644 --- a/src/Drivers/Gd/Encoders/WebpEncoder.php +++ b/src/Drivers/Gd/Encoders/WebpEncoder.php @@ -13,8 +13,9 @@ class WebpEncoder extends DriverSpecializedEncoder { public function encode(ImageInterface $image): EncodedImage { - $data = $this->getBuffered(function () use ($image) { - imagewebp($image->core()->native(), null, $this->quality); + $quality = $this->quality === 100 ? IMG_WEBP_LOSSLESS : $this->quality; + $data = $this->getBuffered(function () use ($image, $quality) { + imagewebp($image->core()->native(), null, $quality); }); return new EncodedImage($data, 'image/webp');