Skip to content

Commit

Permalink
Set lossless quality for GD WebpEncoder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olivervogel committed Dec 19, 2023
1 parent a1da8e2 commit bc09f0d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Drivers/Gd/Encoders/WebpEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit bc09f0d

Please sign in to comment.