craft-snippets / Craft-image-toolbox

Craft CMS plugin that helps with the use of image transforms in templates.
Other
16 stars 0 forks source link

Webp support #5

Closed CreateSean closed 3 years ago

CreateSean commented 3 years ago

Locally I am able to see webp images generated. However on my forge/digital ocean server with ubuntu 18.04 webp is not working so I installed webp like this:

sudo apt install webp

However that doesn't appear to have worked. as when I add this conditional to my code I get the no webp support

  {% if craft.app.images.supportsWebP() %}
    webp support
  {% else %}
    no webp support
  {% endif %}

I also checked php info and it shows webp support enabled image

Is there something else I need to do to get webp to work with image-toolbox on my server?

piotrpog commented 3 years ago

Image toolbox internally uses internally Craft getSupportsWebP function to check for webp support.

Can you check what dump(craft.app.images.getSupportsWebP()) will return in Twig?

CreateSean commented 3 years ago

Adding that code gave me an internal server error on the live site, but when I changed it to this:

  {% if craft.app.images.supportsWebP() %}
    webp support
  {% else %}
    no webp support
  {% endif %}

it returned no webp support.

However in discord I discovered that other plugins, Image Optimizer and Imager-x support another way to get webp support by adding cwebp to your install. https://discordapp.com/channels/456442477667418113/456448961679589386/812707914174955539

It seems that the reason this isn't working with image-toolbox is that ubuntu 18.04 doesn't support webp so you need to install cwebp and ensure that any plugins support that extension.

I checked on another site I have on a ubuntu 20.04 server and webp works as expected.

If you could add in cwebp to image-toolbox to support sites on older servers that would be great, but if not, while disappointed I understand.

piotrpog commented 3 years ago

@CreateSean I think i have idea how your issue can be solved - i will just add option to force usage of webp, even if Craft built in function (erroneously) detect that there is no webp support on server.

CreateSean commented 3 years ago

Excellent, looking forward to it. Thanks.

piotrpog commented 3 years ago

@CreateSean 1.1.0 version with forceWebp setting was just released.