Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of auto converting to WEBP #185

Closed
umkasanki opened this issue Jan 7, 2020 · 5 comments
Closed

Add support of auto converting to WEBP #185

umkasanki opened this issue Jan 7, 2020 · 5 comments

Comments

@umkasanki
Copy link

Could you add feature automatically convert JPEG to WEBP if the client browser it's supported? Like it works in IMGIX with format=auto. (AWS Server­less Image Han­dler already supports this feature)
I know what possible to use tag with source param, but simple markup of img tag is much handier.Thanks

@karensg
Copy link

karensg commented Jan 8, 2020

Would be great indeed.

@khalwat
Copy link
Contributor

khalwat commented Jan 8, 2020

Seems like it'd be possible. So if you do {{ someAsset.optimizeImages.srcset() }} you want it to auto-use webp if the browser supports it?

@umkasanki
Copy link
Author

Yes, it will be great

@khalwat
Copy link
Contributor

khalwat commented Jan 8, 2020

So I started to work on this when I realized it probably can't be done the right way. If I did it as I was thinking of doing it, it'd break when a site is static cached, or otherwise the output of the Twig template is cached.

The reason why services like Imgix can do it is they respond to the actual request for the file itself. So if you request:

https://example.com/image.jpg

...the webserver can look at the accept headers, and send back something else (a webp in this case). Requests for static resources like images shouldn't normally be routed through Craft, because they will be super slow if they are, thus Image Optimize would never have a chance to work this magic.

However, the Image Optimize documentation mentions how you can do the same thing on your server that Imgix and other such services do:

https://nystudio107.com/docs/image-optimize/Using.html#image-variants

Recipe: serve WebP with nginx conditionally

@khalwat khalwat closed this as completed Jan 8, 2020
@karensg
Copy link

karensg commented Jan 8, 2020

Thanks for your explanation, I am using Cloudfront with AWS image service. https://aws.amazon.com/solutions/serverless-image-handler/
Picture element works great. Only for the css there is no clean solution unfortunately.

There is this PR available at the moment: aws-solutions/serverless-image-handler#152
I guess when this is merged, we could set up Cloudfront to cache based on Accept header and let this service handle webp transformations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants