JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 141 forks source link

Control quality for webp etc #204

Closed badbadmonkey closed 1 year ago

badbadmonkey commented 1 year ago
  1. How does one control the quality in Webp or other lossy formats like AVIF, is the q factor used same as JPEG?

I am testing this and I get webp's of the same size regardless of how q is set, so I presume it's ignored atm. If I'm wrong please advise. They are also quite large so must be defaulting to a fairly high quality.

  1. Equally, we need a way to specify generation of lossless Webp etc. vs lossy. q=100 ?
honzito commented 1 year ago

WEBP Quality parameter q=1-100 now works in GD backend and also in ImageMagick backend ($PHPTHUMB_CONFIG['prefer_imagemagick'] = true;) BTW: The quality parameter is in ImageMagic supported from v 7.0.8-68, which (in most cases) is not yet on the server.

see https://github.com/JamesHeinrich/phpThumb/pull/211#issue-1717476776

badbadmonkey commented 1 year ago

Is q=100 lossless?

honzito commented 1 year ago

No. As I looked in the phpThumb code, the q is rounded to range 1-99 internally. There is no support for loseless WebP in phpThumb, yet. The support for loseless WebP in PHP is from version 8.1 (with q=101 (IMG_WEBP_LOSSLESS)), so it is doable (https://php.watch/versions/8.1/gd-webp-lossless). I'm not sure, how it is with ImageMagick backend for phpThumb...

badbadmonkey commented 1 year ago

Thank you honzito. I got webp q working.

What about AVIF ?