Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I tested this great module with my images - PNG files. But webp files were not generated.
After some digging I've found in Webp.php file on line 86 this condition:
if ($sourceImage !== NULL && $mimeType !== 'image/png') {
Tha's why my png was not converted.
1) why is there this condition - is it safe to remove it?
2) it should be at least mentioned it on the project page on in the README file
Thanks
Comment | File | Size | Author |
---|---|---|---|
#22 | webp-png_support-2992795-21.patch | 1.72 KB | alexmoreno |
Comments
Comment #2
ckaotikI have no idea why PNGs are disabled, they can be generated just fine. I've attached a patch to remove this restriction.
Comment #3
lobodakyrylo CreditAttribution: lobodakyrylo commentedI suppose WebP doesn't support transparency so it's disabled. Maybe it's better to create an option to enable/disable PNG support on the setting page.
Comment #4
RedEight CreditAttribution: RedEight at 95Visual commentedWebP does support transparency though. It also supports animations so it could possibly replace gif as well.
Comment #5
seaarg CreditAttribution: seaarg as a volunteer commentedI was facing the same issue and xdebug trace showed me the same issue. After removing the image/png mimetype conditional everything started working fine. Patch in comment #2 worked for me.
Using 7.3.4-1+ubuntu16.04.1+deb.sury.org+3 with GD ext.
If you have the time, can you please explain why that conditional was there? Perhaps there are specific PNG conditions when webp generation fails?
Comment #6
lobodakyrylo CreditAttribution: lobodakyrylo commentedAfter some research, I've found that this module uses imagewebp PHP function. For some reason, it doesn't convert PNG files correctly. It skips the alpha layer. At least it doesn't work for PHP 7.0.33-0ubuntu0.16.04.3. Transparent images don't even work for 7.3.4-1+ubuntu16.04.1+deb.sury.org+3 with GD ext.
Comment #7
lobodakyrylo CreditAttribution: lobodakyrylo commentedMaybe I have a corrupted GD version, I downloaded it using apt-get command though.
I forced the module work with transparent images after installing cwebp on my server and changing the module code.
WebP installation instruction: https://developers.google.com/speed/webp/download
Be sure that my patch not safe. It probably will not work on servers that do not support exec function.
Comment #8
Nigel CunninghamRe the patch in 7, it needs quotes around the filenames to deal with spaces in file and directory names. Here's a modified version.
Comment #9
Bart Vanhoutte CreditAttribution: Bart Vanhoutte commentedIIRC I disabled PNG support because of a bug in some version of libwebp where transparancy in PNGs is not converted properly. Feel free to add a configuration option to enable it or add some code that detects the version of the library and act accordingly.
Comment #10
alexmoreno CreditAttribution: alexmoreno commentedthis patch does not apply anymore, as the code in 1.0@beta already contains that if condition removed
Comment #11
alexmoreno CreditAttribution: alexmoreno commentedre-rolled against dev.
IMO makes sense to use exec instead of native php. I have heard the png issue, if this fixes it it's a great addition, thanks a lot everyone that has contributed to this.
If anyone could re-test this patch and confirm it's working for them too, that'd awesome as well :-)
Comment #12
alexmoreno CreditAttribution: alexmoreno commentedpatch re-rolled against dev changes
Comment #14
alexmoreno CreditAttribution: alexmoreno commenteddone several tests, with and without patch. Looks good to me, so merging it
Comment #16
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedI don't think using exec is the right approach. Many servers and website hostings have exec disabled for security reasons and I think the module should offer an option to select which backend to use for WebP conversion.
Comment #17
alexmoreno CreditAttribution: alexmoreno commentedComment #18
alexmoreno CreditAttribution: alexmoreno commented@lobodacyril did you find any specific reason why imagewebp would not work?
I would like to re-open re-review this, agree with @Klemen Pevec
This is a blocker before releasing a stable version or even a new beta or RC
Comment #19
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedI have checked some old commits of this module and my guess based on a quick read on PHP GD is that one needs to enable alpha channel on the image before calling
imagewebp
like this:I did not test this as I am not really familiar with PHP GD or this module's codebase, but I thought this might help.
Comment #20
rrotariThis is a version without exec function although doesn't always have same results, is server dependent.
Comment #21
alexmoreno CreditAttribution: alexmoreno commentedwould those functions not be compatible with png? I'd rather find a function that works for all instead
Comment #22
alexmoreno CreditAttribution: alexmoreno commentedremoving the exec function and adding imageAlphaBlending and imageSaveAlpha
Comment #23
alexmoreno CreditAttribution: alexmoreno commentedwould be great to have this tested. Once we are all happy and check that it's working I want to cut the last beta, wait a reasonable amount of time and launch a first stable version, so we can also get some eyes from the sec team
Comment #24
alexmoreno CreditAttribution: alexmoreno commentedI have done some tests and looks pretty good. I will try a few more png's from different sources and scenarios and merge it before end of weekend, if anyone wants to have a test you are welcome :-)
Thanks all for working and helping with this.
Comment #26
alexmoreno CreditAttribution: alexmoreno commentedComment #27
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedThank you for fixing this. I hope this gets in a release soon.
Comment #28
Bohus UlrychYes, thank you for fixing this.
Comment #29
alexmoreno CreditAttribution: alexmoreno commentedAbsolutely, if we can confirm that this is working, I am happy to release a new beta preparing for the first stable release.
Just install the dev version and let me know. Thanks a lot, good teamwork :-)