Jump to content

WebP is not generated if source PNG already has target size


thausmann
 Share

Recommended Posts

Hey, I'm trying to completely switch over to WebP and noticed some strange behaviour. Let's say I upload a PNG in Processwire of size 1280x800.

  • $page->image->url ➝ correct URL (filename.webp)
  • $page->image->width(800)->url ➝ correct URL (filename.800x0.webp)
  • $page->image->width(1280)->url wrong URL (filename.1280x0.png), webp file is not generated
  • $page->image->width(1280)->url(false)correct URL (filename.1280x0.webp) but webp file is not generated

So: When I request a size that equals the original file, no WebP conversion is happening (no webp file is created, although a new PNG is generated (...1280x0.png)).
When I use url(false), I get the expected URL but still the file is not generated. Also interesting: this issue is only occuring with PNG, not JPG.

 

My Configuration:

$config->imageSizerOptions('webpAdd', true); 
$config->imageSizerOptions('defaultGamma', -1); 
  • GD
  • Pageimage::url Hook from here 
  • Also tried to output width(1280)->webp->url, it makes no difference
  • I checked that the PNG version is not smaller in filesize (PNG=450KB, WebP (from other tool)=60KB)
  • Tested with Processwire 3.0.148 and 3.0.160 dev
  • I think this post is about the same issue and where I got the url(false) from.
  • Setting 'useSrcUrlOnFail' => false inside $config->webpOptions results in correct output URL (filename.1280x0.webp), but still the file is not generated. So maybe the webp conversion fails? Apparently I see zero webp logs in logs/image-resizer.txt

 

"Don't use resize" seems like a solution here but this is a generic approach in my code, sometimes uploaded images are simply already in the correct size. 

Any ideas how to fix this and always get dem sweet sweet WebP images? Or did I find a bug?
Maybe @horst has an idea what the cause of this phenomenon could be? ?

Link to comment
Share on other sites

16 minutes ago, horst said:

Have you also tried this:


$page->image->width(1280)->webp()->url

 

Thanks for your reply! I just tried that and apparently it gives me the same png url filename.1280x0.png.

As soon as I go 1 pixel up or down I get a webp URL. 

Link to comment
Share on other sites

17 hours ago, thausmann said:

Thanks for your reply! I just tried that and apparently it gives me the same png url filename.1280x0.png.

This is weird. Please can you post an issue on GitHub with this, so that Ryan gets informed about it?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...