Drupal 9.2 supports the webP image format (see change record: https://www.drupal.org/node/3171135).
In order for browsers that do not support WebP (earlier versions of Safari & IE), the image needs to be wrapped in a <picture>
tag like so:
<picture>
<source srcset="my-awesome-picture.webp" type="image/webp">
<img src="my-awesome-picture.jpg" alt="Awesome">
</picture>
Older browsers will look at the type attribute on the <source>
element, and fallback to the <img>
element.
This is next to impossible to do with Drupal core (although you can get it working in an extremely hacky way!)
The breakpoint module gives you the option to select media queries and multipliers, but does not give you an option to select the type
.
I do not have an option to create multiple image styles on a single media query. I can hack this by creating multiple media queries such as 'all and (min-width: 1x)'
and 'all and (min-width: 2x)'
. But this is just plain ol' wrong.
Note this is solved in contrib through the https://www.drupal.org/project/webp or https://www.drupal.org/project/imageapi_optimize_webp modules. for Drupal 9.x There is no Drupal 10 support for those modules (yet).
Comment | File | Size | Author |
---|---|---|---|
#23 | 3213491-nr-bot.txt | 150 bytes | needs-review-queue-bot |
#20 | responsive_image_form.png | 138.21 KB | finnsky |
Issue fork drupal-3213491
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mherchelComment #3
mherchelComment #4
andypostWhat is required to fix it?
Comment #5
AnybodySeems to me that webP only "works" on responsive images, not "native" images? Is this solvable in core at all as it means the result of the image style wouldn't be an
<img>
anymore but a<picture>
once someone selects to convert it?@mhercel: Could you find out which browsers in this liste are affected? https://www.drupal.org/docs/system-requirements/browser-requirements
Update:
Affected browsers:
See https://caniuse.com/webp
Comment #6
AnybodyIf this might be unsolvable for image formats (at least for older browsers) in the meantime core should perhaps adopt an option to responsive image styles instead?
The option for image formats could be kept, if everyone knows what he's doing... or add a warning note to the image effect?
Comment #7
AnybodyComment #8
saschaeggi@Mike you could check the existence of WebP images and serve them if supported. In Apache this could look similar to this:
.htaccess:
Comment #10
catchJust found this issue and had a think about it / did a bit of research.
https://www.drupal.org/project/webp supports fallbacks for webp images for browsers such as IE and Safari from contrib.
Drupal 10 has dropped support for all versions of IE, so we wouldn't add any new features to support IE specifically.
The latest couple of versions of Safari support webp, but only if you're on Big Sur or later. Catalina support is going to end in approx November 2022.
https://caniuse.com/webp
This means if we add some kind of polyfill via picture module for webp to core, it would fall under our browser support matrix for the next six months, but then be eligible for removal again - potentially still for 10.0.x if we end up releasing in December. Given there's not a viable patch here, I would tend to suggest that people use the contrib module for full webp support, and core's webp support will be sufficient for all modern browsers/supported OSs in approximately 6-9 months anyway. If there's another browser we support that can't handle webp yet though that might tip the balance towards adding this to 10.0.x
There's a further question whether we want to add a generic feature of allowing a format aspect to responsive image styles to address similar kinds of issues in the future - that might mean converting this to a task. This seems to be the only viable implementation here, we can't do it via pure image formats.
Comment #11
catchA further issue, due to an Apple bug, it's not possible to tell the relative usage of Catalina vs. Big Sur, because Big Sur reports itself as Catalina.
See the note and link on top of:
https://gs.statcounter.com/macos-version-market-share/desktop/worldwide
Comment #12
catchGoing to go ahead and close this as won't fix.
Core currently makes it possible to configure a site such that it won't work on IE / and <= Catalina MacOS, but you have to intentionally configure it to transform images into webp.
Catalina support will end in approximately six months, that's the only configuration that Drupal 10 supports since support for all versions of IE was already dropped, and it probably won't be supported by the time Drupal 10 is released. If we had an RTBC patch here and it was a year ago, it might have been worth providing the workaround for webp support on Catalina, but at this point we'd be adding what is essentially a feature to responsive image module that will be obsolete in a few months. The contrib webp project is already there for sites that want to support IE/Catalina.
Comment #13
AnybodyThanks for caring, @catch! Totally agree with the decision due to the reasons given.
Comment #14
catchRe-opening this in light of #3202016: Let GDToolkit support AVIF image format which would add support for the AVIF format. AVIF also has (currently) spotty browser support, so it'd be viable to set up something like avif with a fallback to webp and then to the original image format.
Comment #15
andypostas a feature it goes to 10.1
Comment #16
andypostOTOH it means that 10.0 will be released with partial WEBP support
Comment #17
catchThis is true but webp has been in for several releases now, so it's not a new situation.
Comment #20
finnsky CreditAttribution: finnsky at Skilld commentedAdded rude mvp.
For every breakpoint we may create set of images.
Should be autocomplete form or draggable table here.
Tested with patch from https://www.drupal.org/project/drupal/issues/3202016 so AVIF was onboard aswell.
Created 2 images styles with convert to formats:
- AVIF
- WEBP
Output was:
In my chrome browser was loaded AVIF, in other WEBP will appear or even single breakpoint failback
Comment #21
finnsky CreditAttribution: finnsky at Skilld commentedComment #22
andyposthttps://caniuse.com/avif needs Safari 16.0 TP to be displayed
Overall great job! added some code-review
Main questions
- why 3 elements in
srcset
is enough to configure?- how to extend/override it and how to configure defaults if webp, jpg I bet is used on mostly all sites and how to fit afiv when patch accepted
Comment #23
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #24
Martijn de WitComment #25
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot for Vardot commentedSupport having this awesome feature
Modules like Image Styles too with Responsive Image Style
and contrib modules like Dynamic Responsive Image (or drimage) will switch from using Webp to the Drupal core solution.
Comment #26
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot for Vardot commentedCan projects start using this fix? If it will be committed to Drupal Core
10.1.x
or10.0.x
Comment #29
GaëlGComment #30
andypostIt needs test and code comments - why 3 is enough!?
Comment #31
Shikha_LNweb CreditAttribution: Shikha_LNweb at LN Webworks Private Limited commentedAnyone who is looking for some module in context of Drupal 10, can probably have a look here :
https://www.drupal.org/project/wpf
This module is good work around in context of fallback image support.