php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

Saving Lossless Webp? #857

Closed jcogs-design closed 6 months ago

jcogs-design commented 6 months ago

Issue description

Since php 8.1 the php GD library supports the saving of images in the webp lossless format using the construct:

imagewebp($image, 'image.webp', IMG_WEBP_LOSSLESS);

where IMG_WEBP_LOSSLESS is a constant set to the value 101.

The saveOrOutput method in the GD\Image.php class has an explicit check (line 734) to prevent the value of the quality parameter exceeding the bounds 0-100.

How in this case then can lossless webp images be saved?

ausi commented 6 months ago

With the IMagick driver you can use the option 'webp_lossless' => true. The GD driver does not support that currently, see https://github.com/php-imagine/Imagine/pull/858

jcogs-design commented 6 months ago

Not entirely sure on what basis this got closed. That you can do lossless using a different library is nice, but that doesn't address the range constraint on GD (which appears to be the only reason GD won't do lossless currently). No more useful closure than saying "use a different library" really. I thought this process would be more inclusive regarding actual issues, rather than whatever it is that is convenient.

jcogs-design commented 6 months ago

With the IMagick driver you can use the option 'webp_lossless' => true. The GD driver does not support that currently, see #858

Actually GD library does support this feature. See here https://php.watch/versions/8.1/gd-webp-lossless The details of this were included in my original post. Perhaps you couldn't find the link to the documentation - hopefully the link above will help.

mlocati commented 6 months ago

Not entirely sure on what basis this got closed. That you can do lossless using a different library is nice, but that doesn't address the range constraint on GD

This issue has been closed because https://github.com/php-imagine/Imagine/pull/858 should fix it. What's wrong with that pull request?

ausi commented 6 months ago

No more useful closure than saying "use a different library" really.

No that’s not what I meant. #858 adds the support of 'webp_lossless' => true for the GD driver.

The GD driver does not support that currently, see #858

Actually GD library does support this feature.

Yes, the GD library does, but the GD driver did not. But as #858 was already merged since, the GD driver now also supports lossless WEBP images (it was not released yet so you have to install the dev-develop version in order to use it in your project).