Karmalakas / grav-plugin-photoswipe

Add Photoswipe gallery to your pages
MIT License
8 stars 1 forks source link

A possible webp support? #9

Closed 01Kuzma closed 1 year ago

01Kuzma commented 1 year ago

Hello! Did you try to integrate the webp support with the gallery? At this moment this grav webp plugin supports image conversion into webp file format. img tags should be appended with these filters:

   <img alt="webp image" src="{{ '/user/images/my-image.jpg'|webp }}">
   <img alt="webp image" src="{{ url(logo)|webp }}">

It it possible to override the template to make such support? Or everything is done in js ?

P.S. it seems that the photoswipe library support webp file format natively (but probably partially?)

Thank you!

Karmalakas commented 1 year ago

I believe you could easily extend main plugin template by copying it to /user/themes/[YOUR_THEME]/templates/photoswipe.html.twig (you'd need some custom theme) and change src on line 13. This should work

Most likely I will not implement this feature in the plugin itself, because it would add one more dependency and not many need this I assume 🤔

01Kuzma commented 1 year ago

Thank you! I will try this! P.S. I presume it should be something like this: <img src="{{ item.cropResize(500, 250).url|e|webp }}" alt=""/>

Karmalakas commented 1 year ago

Probably yes. Would need to test with Webp plugin installed. Or maybe |e is not needed at all in such case

01Kuzma commented 1 year ago

Just one question: are you sure that overridden template file should be placed here: /user/themes/[YOUR_THEME]/templates/photoswipe.html.twig not in a deeper folder? As an example /user/themes/[YOUR_THEME]/templates/plugins/photoswipe/templates or other folder ? Now I'm experimenting with it and overridden twig template doesn't make any difference... ALready placed in different folders...

Karmalakas commented 1 year ago

Seems to be working fine for me 😕 Try clearing caches image

01Kuzma commented 1 year ago

Understood! Thanks for tip ;)

Karmalakas commented 1 year ago

Did you manage to make it work? Just curious 🙂

01Kuzma commented 1 year ago

Unfortunately no, I tried yesterday, but webp was not loaded... I will try further to investigate it. The problem is that webp plugin doesn't work on my localhost, so it's harder to debug the problem