Edit: now we have Drupal CMS for out-of-the-box decent default config of responsive images, webp support in core,... There's always room for improvement so we may keep this meta issue open (to reference more precise related issues), but my initial statement below is largely obsolete.

For your curiosity, this is how the HTML of a blog post image looks like out-of-the-box in Drupal CMS 1.1:

<picture>
                  <source srcset="/sites/default/files/styles/5_2_1300x520_focal_point_webp/public/2024-12/DrupalCon-Barcelona-2024%20-%20credit-Bram-Driesen.webp?h=d607be85&amp;itok=_JtAQX35 1x" media="all and (min-width: 1000px)" type="image/webp" width="1300" height="520">
              <source srcset="/sites/default/files/styles/5_2_1000x400_focal_point_webp/public/2024-12/DrupalCon-Barcelona-2024%20-%20credit-Bram-Driesen.webp?h=d607be85&amp;itok=V_0Fbv9B 1x" media="all and (min-width: 700px)" type="image/webp" width="1000" height="400">
              <source srcset="/sites/default/files/styles/16_9_704x396_focal_point_webp/public/2024-12/DrupalCon-Barcelona-2024%20-%20credit-Bram-Driesen.webp?h=d607be85&amp;itok=DnSosyal 1x" media="all and (min-width: 500px)" type="image/webp" width="704" height="396">
                  <img loading="eager" width="512" height="288" src="/sites/default/files/styles/16_9_512x288_focal_point_webp/public/2024-12/DrupalCon-Barcelona-2024%20-%20credit-Bram-Driesen.webp?h=d607be85&amp;itok=iSxWFT9g" alt="Large group of people at DrupalCon Barcelona 2024 posting for a group photo.">
  </picture>

Problem/Motivation

It's possible to configure responsive images in Drupal so as to optimize their loading time by using modern HTML5 image features: picture, sizes, srcset,... (not to mention modern image formats such as webp, avif,...).

But:
- it's not easy to understand how to do (even more if you're not familiar with those HTML5 features)
- it's not easy/quick to do it in the Drupal admin UI, nor to maintain it (avoid mistakes, make changes afterwards,...)
I have no survey data to support these assertions, but I think anyone who tried could agree.

As a consequence, I guess most Drupal users do not use responsive images or use them poorly, especially the beginners.

First, it's not great because we Drupal want to be easy to use for everyone (see https://www.drupal.org/about/values-and-principles). But it also means having good responsive image defaults or at least a good admin UI or wizard would have much impact on:
- performance of page loads, especially for not-so-good-networks and not-too-demanding devices
- network and device resources consumption, thus ecological footprint
- search engine optimization (because of better performance)

Plus: I guess this would also apply to decoupled websites as soon as they use the markup generated by Drupal responsive image module. And it could even impact non-Drupal websites if the way we handle it becomes a model for other CMS/frameworks.

Oh, and if you're interested about my motivation to create this issue queue, it comes from this discussion with @mgifford on the sustainable Drupal slack channel in January 2022 (!):

Mike Gifford (CivicActions) 15 h 17
The reference to Drupal here https://web.dev/uses-responsive-images/ doesn’t seem to be all that good. Is there a better place to send folks?

Also, is this the best way to optimize image sizes - https://www.drupal.org/project/imageapi_optimize

GG : Many great things can already be done with Drupal to optimize images, but it requires some craft to configure modules, image styles and so on. See for example this Drupal website: https://fne.asso.fr/ (picture, srcset, webp,...). Most of the time, respecting the recos from Google Page Speed/Lighthouse is a good way to optimize. To me, what lacks on this with Drupal is easy configuration (not to say good out-of-the-box defaults).

MG : Well, how do we bring that into Core? Surely we'd want performant sites by default. What could be done to make it easier for future releases? Let us know @GaëlG

GG : It's a big topic and would need much work, but on the face of it, some ideas: webp derivatives by default in core (jpg fallback thanks to <picture>), native lazyloading (this one is in progress), non-technical helpful field descriptions in responsive image config forms (breakpoint_group, sizes,...).
And what would be neat is an image style creation wizard generating a basic responsive image style and the associated image styles of different sizes for different screens from given image proportions (a crop type). This one is hard to think because of the multiple ways images can be used, but there are some common usages (fixed height/width ratio through crop and original height/width ratio seem to be the most common to me). It's a bit like Views: they can be used in many ways but we have a creation wizard with main questions that provide decent defaults. Actually, non-config image styles (entirely computed from a configurable responsive image style) even seems like a good idea to me.
Disclaimer: I've got some ideas because I worked on this kind of needs for our projects, but not much time or money to make happen this kind of core initiative...

Ludo.R il y a 6 jours
Sounds nice! :visage_légèrement_souriant:

Mike Gifford (CivicActions) il y a 2 heures
Can you draft up something in more detail @GaëlG and see if we can’t either bring more resources to implement it or find someone with the cash?? Implementing a performance improvement on a million sites would have a significant improvement on our collective CO2 emissions.

GG: I will take some time to write a core idea (https://www.drupal.org/project/ideas), if there is good chance some attention/time/ressources/money can be given to it. Not today though.

Steps to reproduce

I guess the recommended/optimized way to just display an image nowadays is something like this:

<picture>
  <source srcset="myimage800.webp 800w, myimage1280.webp 1280w, myimage1440.webp 1440w, myimage2048.webp 2048w" type="image/webp" sizes="100vw">
  <source srcset="myimage800.jpg 800w, myimage1280.jpg 1280w, myimage1440.jpg 1440w, myimage2048.jpg 2048w" type="image/jpeg" sizes="100vw">
  <img srcset="myimage800.jpg 800w, myimage1280.jpg 1280w, myimage1440.jpg 1440w, myimage2048.jpg 2048w" sizes="100vw" src="myimage.jpg" alt="something" loading="lazy" typeof="foaf:Image" width="42" height="42"> 
</picture>

(here my sizes attribute value assumes the image will be displayed full-width on all devices, it's an example value for sizes and a decent default if we don't know)
(actually the very best recommended way should be discussed, for example I'm not even sure the widths I offer in my example are the best ones to handle the most common devices)

To do this in Drupal, I have to use the webp contrib module (or some other contrib/custom module). And I have to understand how to configure adequately the not-so-clear responsive image style admin UI (breakpoint groups, breakpoints, multipliers,...).

But let's put that aside. The main struggle is that before I can configure my responsive image style, I have to configure many non-responsive image styles, one for each offered width (800w, 1280w,...). They will all be configured in the same way, with just a different width. Fortunately, there's a contrib module to ease the creation of those images styles: https://www.drupal.org/project/easy_responsive_images But then, if I want to fix/change something about the image styling, I should fix/change all them manually in the same way.
Most of the time, on a website, there are images displayed at their original aspect ratio (in content bodies for example), and images displayed at various aspect ratios according to the mock-ups (16:9, 3:4, 4:3, 1:1,...). Before responsive images, let's say N image styles needed to be configured. To get responsive images offering 4 widths, it's now 4*N image styles. And we may (should?) offer more than 4 widths for an image.
From an UX point of view, it's a bit odd. For a given aspect ratio, I'd expect to be able to configure everything once at a responsive image style level.

Proposed resolution

I did not create a core initiative proposition for now because I'm not sure it needs to become one and I can't/won't invest much time/energy in making the initiative become reality. However, I create this issue because if others could help with that, it would be a shame not to have tried. What I can give is some basic advice on what would be helpful from a site builder point of view (as I did here), and maybe how we could try to approach some problems at the code level (but I'm not an experienced core dev at all).

Anyway, I guess this issue would first need some exploration phase following the steps at https://www.drupal.org/community-initiatives/proposing-initiatives#s-pro...

And maybe a BoF at next DrupalCon?

I also guess this issue would eventually be divided into child issues and follow ups, the main one being to have "non-config image styles".

PS: I won't be available to read/answer comments in the coming weeks. I will afterwards. But if you read me, I want you to know that this issue is not more mine than yours.

Remaining tasks

To be defined.

User interface changes

To be defined.

API changes

To be defined.

Data model changes

To be defined.

Release notes snippet

To be defined.

CommentFileSizeAuthor
#2 responsive-image-styles.png228.89 KBseanb

Comments

GaëlG created an issue. See original summary.

seanb’s picture

StatusFileSize
new228.89 KB

Thanks for this issue! As the maintainer of the Easy Responsive Images module, I have struggled with this before. When working with responsive images in core, the following issues were the most important reasons we created the Easy Responsive Images module:

  • You need to create a lot of image styles, most of them are similar. Maintaining them is quite troublesome as the site continues to grow.
  • Configuring responsive image styles is quite complex, you need to first create all the image styles, then the responsive styles for all breakpoints, and then configure them on a formatter for your fields. This is not very intuitive.
  • The picture element selects images based on the browser width, not the width of the image container. This is a problem for component-based designs where a block can be used in a 2/3/4 column grid for example.

You need to create a lot of image styles / Configuring responsive image styles is quite complex
Since the amount of use cases is huge, it is very hard to come up with a solution that is easy to use, yet supports everything. It would already greatly help if all the configuration for responsive images can be done in 1 place, letting it generate the image styles it needs in the background. As long as it cleans up/updates generated styles when you change things (maybe even lock generated styles and hide them), they won't complicate the interface for "regular" image styles.

The responsive image styles could then be an interface similar to regular image styles, just with breakpoints.
Responsive image styles.

The picture element selects images based on the browser width, not the width of the image container
This would definitely need a JavaScript-based solution at the moment. There is awesome work being done to make the sizes attribute for images support the "auto" value. That would be amazing, and it could be worth it to wait for this. Or we could just accept the limitations for now and already move from picture elements to image elements with sizes attribute.

Output WebP for image by default
This is currently done using the WebP module or ImageAPI Optimize WebP. I agree, it would be nice if core would just do this. All major browsers support it, so not sure if there is a good reason not to? It could be a checkbox on the responsive image style and image style entity forms to opt-in or opt-out?

Other improvements
These tasks above already seem quite actionable and provide quite significant improvements. Some other things that might even improve it more:

  • Allow defining separate breakpoints for containers in the breakpoint module. The current breakpoints seem intended for the browser viewport. Container breakpoints are really something different.
  • Allow an effect to be applied to all breakpoints at the same time. Specially if you have multiple effects and a bunch of breakpoints, this could save some time. An aspect ratio effect could be applied to automatically calculate the correct width / height of an aspect ratio for the image style and (container) breakpoint.
heddn’s picture

I love the ideas expressed here. I even proposed it as an effort that _needs_ get done. However it wasn't sponsored at the time. Anything we can do to improve the UX/DX in this space would be GREAT.

If this is a meta/plan issue, we should start to link more items here. To that end, I've re-tagged as a plan and added references to:

catch’s picture

Issue tags: +Field UX

The responsive image configuration issues discussed in #2 are just about in the purview of field UX (given you end up selecting responsive images in field formatter configuration), so adding that tag.

https://github.com/whatwg/html/pull/8008 seems like it's starting to happen already, so we should definitely open an issue to support that, then we've got a chance of it working when the support is more widespread.

sam152’s picture

I had a crack at something similar in contrib, yonks ago: https://www.drupal.org/project/responsive_image_automatic

lauriii’s picture

Glad to see this problem is being raised here. I've been in a several discussions where this has come up. Drupal Core Responsive Image module is really powerful but at the same it can be time consuming and complicated to configure it properly. I'm happy to support the efforts where needed to the extent I can. 😊

I've personally really enjoyed using Next.js Image plugin. It makes setting up and configuring responsive images really easy. It doesn't provide all of the flexibility that Drupal Responsive Images module provides, but maybe it's worth revisiting if we need all of that flexibility.

prudloff’s picture

webp has been part of drupal core since 9.2

What the webp support in core lacks is having an automatic jpeg/png fallback in picture tags for browsers that don't support WebP. (And the same logic could also apply to AVIF.)
The webp contrib module does that and #3213491: Add fallback format support to responsive images discusses adding this functionality to core.

catch’s picture

The fallback is less necessary for webp specifically because browser support is pretty much universal now, the last holdout I knew of was pre-2015 Macs, which also can't be detected via usage stats due to some weird decisions by the osx team. We decided that was an anomaly as far as #3275557: Add webp image conversion to core's install profile's image style was concerned so implemented default webp in the standard profile for 10.2.x

However, #3213491: Add fallback format support to responsive images will be useful for avif or any other new format that arises, so we should still try to add that.

andypost’s picture

In a perfect world the resulting image format should depend on image, webp vs avif - mostly always the later wins

dimiter’s picture

@seanB, @GaëlG :

To do this in Drupal, I have to use the webp contrib module (or some other contrib/custom module). - @GaëlG

Output WebP for image by default
This is currently done using the WebP module or ImageAPI Optimize WebP. I agree, it would be nice if core would just do this. - @seanB

As of Drupal 10 (I think) 9.2 according to @heddn in #3 above, Core is able to provide WebP support out-of-the-box for images styles. It is hidden away out of sight, so I do agree it is hard to find. To enable it, you have to add the 'Convert' action to an image style, and you will be able to select WebP as the desired format. I think that the fallback issue should still be solved in Core, but for now it seems that the https://www.drupal.org/project/wpf (WebP Fallback Image) module is able to handle that in a nice way without the need for additional configuration or setup. What I like about this approach is that the site will be serving WebP images by default, and will only need to do additional processing for the fallback images that are required.

I do agree that it is pretty time-consuming nowadays to setup high-performance images using Core. The number of required images sizes will only grow over time (2x multiplier is already considered 'default' by now, 3x is already being used by modern iDevices but not often implemented, and its just a matter of time before the 4X multiplier will be introduced...) . If you would want to support all that for a full-width hero-image (which is a common use-case), also providing efficient images for use on mobile, you will already need quite some configuration and setup. Having something that makes this easier (e.g. the module mentioned/created by @seanB) would be much appreciated.

heddn’s picture

Dropping the notes from my research of the 2 modules I've come across that try to help in this space:

  • responsive_image_automatic was written 7 years ago and is feeling its age. the ideas in there are GREAT, but it doesn't add any 1.25, 1.5, 2x, 3x multipliers. maybe with a bit of work, it could be a real contender if it were modernized.
  • easy_responsive_images is a recent addition, assumes use of contrib webp support (not core), and uses a resizer javascript helper script

Are there other options to review? While rough, I really liked the simplicity of responsive_image_automatic. With a little bit of dusting off, I think it could really do a lot of things here.

milos.kroulik’s picture

Thanks for the research. I've updated responsive_image_automatic module so I can test it in Drupal 10.1: https://github.com/miloskroulik/responsive_image_automatic.

Apart from missing multipliers, it (probably obviously) doesn't support lazy-loading of responsive images, which has been introduced in D 10.1.

heddn’s picture

Following the work in that github repo.

milos.kroulik’s picture

There's also another module - https://www.drupal.org/project/drimage, that seems to be very similar to https://www.drupal.org/project/easy_responsive_images:

  • it needs a JS code to work
  • it integrates with focal_point and imageapi_optimize_webp

But it provides an image field formatter, which makes the setup very quick.

I've done some basic testing - it seems to be working fine on the frontend, but JS file is currently not loading in the CKeditor (https://www.drupal.org/project/drimage/issues/3079190 - but it looks like there's some workaround).

heddn’s picture

re #14: that looks pretty nice. I wish it would do its thing without js/css though. And it would support native/core webp instead of requiring a contrib module.

milos.kroulik’s picture

It looks like there's a tradeoff - either you can generate images based on a static configuration (increases in viewport width), like responsive_image_automatic does or you need to use a JS to scale the image based on the dimensions of the container.

But I wonder, if it would make sense to generate the image styles and responsive image mappings automatically based on a "template" image style (which could for example define the webp conversion) and the theme.breakpoints.yml file. Actually, there are 2 modules which allow to create image styles programatically (https://www.drupal.org/project/image_styles_builder and https://www.drupal.org/project/image_style_generate) already.

Then again, it looks like there might a browser-based solution for container queries-based responsive images on the horizon: see https://www.stefanjudis.com/notes/should-responsive-images-work-with-con...

heddn’s picture

From a predictability perspective, I'd want a starting place and some sizing parameters defined in the field formatter. I also want to be able to set all of this in the Node view mode (not in media view mode). It feels a little scary to have a module that automatically generates image styles without any limits. Could easily lead to a DDoS and filling up the disk.

I also want 1.5x, 2x, 3x and (soon) 4x image styles that increase the size of the image but also reduce the image quality to 50% or 30%.

All of this should put the experience of building styles for responsive images front and center. Maybe there could be some integration w/ https://ausi.github.io/respimagelint/ to instantly test the built styles?

catch’s picture

For configuration on the node view mode we'd need #2947796: Responsive image format for media.

For #16 something like that seems like a good idea. I think what you're suggesting is you start with one manually created image styles, and then responsive image module when you're creating a responsive style gives you the option to generate variations based on the same aspect ratios. It would allow for what srcset and sizes attributes can do. Completely manual configuration with different aspect ratios is still there either for different aspect ratios/cropping rules or just fine tuning.

dimiter’s picture

How about an interface where instead of generating image styles, you can define aspect ratios to use (e.g. 1/1, 4/3, 16/9, etc). Then, for each aspect ratio, you can (manually) define the widths for which to generate image styles (e.g. 120px, 320px, 640px, 1200px, etc). Additionally, you could enter / select a range of multipliers (1x, 1.5x, 2x, 3x, 4x) to use. All that combined will result in a matrix that can generate all required image styles beforehand without the need for Javascript during runtime. Added benefit is that because the aspect ratio is the same, the image styles for the larger breakpoints can also be injected into the smaller breakpoint (e.g 2x 640x480 can also be used as 1x 1280x960).

This does allow the freedom to decide which breakpoints and image sizes to generate. Each of these entries could also have (some of the) effects applied to them. For example, the WebP transform or black/white effects could be applied without problem, but the various scale and/or resize-options wouldn’t work.

heddn’s picture

I do like #19, but I have concerns about re-using image styles that are 1x in one place for 2x, 3x, etc in other places. The image quality for 2x and 3x doesn't need to be 80%+. A quality of 30-50% is sufficient. Because while mobile devices can render greater pixel density, the human eye cannot tell the difference between 30% 2x and 80% 2x and the size saving for a 2x 30% is significant enough to justify making a different image style.

dimiter’s picture

I hadn’t thought about that, seems to be a fair point (although I’m not sure if I would go as low as 30%, but that’s a concern for later).

While my suggestion from #19 is not yet what I would call ‘out of the box’, it would be much easier to configure for a large amount of image sizes/ratios. Of course, it would be possible to supply some (optional) default configuration, that e.g. provides the 4/3 ratio by default with some common used widths (320px … 1200px … 2500px?) in 1x and 2x multipliers, in WebP, that would improve the ‘out of the box’ experience for new setups.

gaëlg’s picture

Hello there, thank you all for the great feedback on this issue! It looks like many people are concerned and have ideas! :)

It may be the good time to start organizing a bit the various problems and ideas discussed here. It's look like there are 3 main questions.

1) What should be the decent/recommended/optimized/default way to display an image in HTML?

picture, source, srcset, sizes, image file formats, multipliers, image quality, breakpoints,... This issue in somewhat Drupal-agnostic, I guess we can get answers elsewhere on the web.

Avenues in comments #1, #4, #17, #20

See also:
https://www.stefanjudis.com/notes/should-responsive-images-work-with-con...
https://github.com/whatwg/html/pull/8008
https://ausi.github.io/respimagelint/docs.html

2) Which technical way to share/pool the creation and also the updates of many Drupal image derivatives needed for a same responsive image display, to get a better admin UX?

ImageStyleInterface should not extend ConfigEntityInterface? Or we should use config at the field formatter level and get rid of the Drupal "image style" concept?
Wizard à la Views?

I believe we need a clearer view in question 1 before going further with this.

Avenues in comments #1, #16, #17, #18, #19, #21

See also:
https://www.drupal.org/project/easy_responsive_images
https://www.drupal.org/project/responsive_image_automatic
https://www.drupal.org/project/drimage
https://www.drupal.org/project/image_styles_builder
https://www.drupal.org/project/image_style_generate
#2947796: Responsive image format for media
#2534058: [META] Usability of Responsive Image in Core

3) Webp and avif conversions by default in core, with fallbacks (at least for avif which is less supported for now)

This seems to be more a task than a question, as there is some consensus on what should be done (maybe not that much on how in should be done?). This is already a work in progress independently from this issue. There could be a follow-up to question 2 to handle question 3 in the new UX paradigm.

See also:
https://www.drupal.org/node/3171135
#3213491: Add fallback format support to responsive images
#3275557: Add webp image conversion to core's install profile's image style
#3282679: Allow user-uploaded WebP images everywhere in Drupal by default: image fields, media library, text editors
#3202016: Let GDToolkit support AVIF image format
https://www.drupal.org/project/wpf
and comment #9



So, do we make this issue a meta and create 3 children issues?

catch’s picture

picture, source, srcset, sizes

I don't think that needs revisiting here. Core responsive images module uses the picture element which has a superset of all the other methods. So they may be cases where it's overkill, but we'd always need to provide it unless browsers deprecate it. We could potentially look at alternative formatters/formatter configuration options when picture isn't needed but that doesn't feel necessary.

heddn’s picture

Great summary in #22. I think bullet 2 is key and will make/break responsive images. They are too hard to setup and manage, so they simply aren't used nearly enough.

seanb’s picture

Great ideas and discussions! Thanks everyone. I think it's definitely a good idea to start using this as a meta issue. We can discuss, share and track possible improvements here.

Some ideas for issues to start improving things:

  • Automatically generate a WebP version for image styles and use the WebP version by default.
    All major browsers support it. Since AVIF is not supported by Edge, we need to check the HTTP_ACCEPT header which makes it harder to cache pages, so I suggest postponing that and add it later.
  • Improve the UI for configuring responsive images.
    We could use #2534058: [META] Usability of Responsive Image in Core for this one (one idea to improve this can be found in #2)
  • Add a responsive image formatter using an img tag with the srcset / sizes attributes
    I definitely think we should consider supporting an img element with srcset / sizes attributes. All major browsers support it. My reasons for this are the following:
    1. It is a more lightweight option.
    2. The extra picture element can make it harder to provide consistent theming and JavaScript.
    3. Once browsers have implemented the sizes="auto" feature. This would allow lazy-loaded images to load images based on their actual size, not the viewport size.
    4. There is a difference, but in core I don't think we are using any features of picture that srcset / sizes don't cover.

    For backwards compatibility, I like the idea of additional formatters for this.

  • Implement the sizes="auto" feature for lazy-loaded images in the new responsive image formatter.
    The spec has landed (https://github.com/whatwg/html/pull/8008). We should postpone this until all major browsers have implemented the feature, but this can definitely improve performance when entities might be rendered in different 1/2/3 column layouts (like block content or paragraphs).
    https://bugs.chromium.org/p/chromium/issues/detail?id=1359051
    https://bugzilla.mozilla.org/show_bug.cgi?id=1819581
    https://bugs.webkit.org/show_bug.cgi?id=253143
prudloff’s picture

Since AVIF is not supported by Edge, we need to check the HTTP_ACCEPT header which makes it harder to cache pages

You don't need to do this. If you generate a picture tag with multiple formats, the browser will only load the AVIF file if it supports this format: https://avif.io/blog/tutorials/html/#implementation

gaëlg’s picture

Title: High-performance images (nearly) out of the box » [Meta] High-performance images (nearly) out of the box

@catch #23: Sorry, I wasn't clear enough. Yes, picture/source can be useful because they allow for file type fallbacks, media queries (notably for art direction),... And even if a picture tag with only one child source tag can be simplified into an img tag, it's not necessary.

I meant: what is a bit more controversial is: most of the time, to display an image (usually a photo), should we use:
- sizes?
- and/or media queries?
- and/or multipliers?
If we use srcset, which widths should be provided? Should we have a different image quality (I mean compression in %, not size in px) depending on the multiplier?

In other words: if I have a source image file and a desired aspect ratio, what should be the resulting HTML, by default in core? My current answer is in the issue summary, but I'm not sure it's the right one. I did not know about sizes=auto but it looks great, as it prevents the need to set the right sizes value according to CSS, which can be difficult and can't be computed as a default.

@heddn #24: Yes, the big need is point 2. But it's easier to discuss if we agree on point 1 before.

@seanB #25: This is now a meta issue :) But before creating most children issues for Drupal implementation tasks (I like your ideas), I think we need to agree on point 1.

@prudloff #26: Yup, there are two ways to serve image formats with fallbacks. One is to look at HTTP_ACCEPT header and serve a different HTML according to it. The other is to use a picture tag. The second one seems better to me because it eases caching. But this is one of the questions on which we should agree before we can set a default system.

gaëlg’s picture

Just referencing this blog post which may help with step 1 of comment #22: https://mariohernandez.io/blog/responsive-images-in-drupal-a-guide/

I also talked to @nod_ which is Provisional Frontend Framework Manager and may help take a decision on step 1.

andypost’s picture

Version: 10.1.x-dev » 11.x-dev
Related issues: +#3406267: All core shipped image styles should include webp conversion
gaëlg’s picture

Issue tags: +sustainability
mgifford’s picture

Great to see this.

This is how Wagtail is currently doing this:
https://wagtail.org/sustainability/
https://wagtail.org/blog/wagtail-greener-and-leaner/

Also an idea for relative CO2 impacts (all estimates of course):
https://sustainablescreen.org/unlocking-sustainable-speed-optimising-ima...

gaëlg’s picture

Thank you @mgifford. I can see that in Wagtail, they seem to have no default value for the sizes and srcset values. So it's up to the "site builder" to define the right values, which can be difficult. I guess in Drupal we should have a decent default, if possible.

https://docs.wagtail.org/en/stable/reference/jinja2.html#picture

rkoller’s picture

One idea I've posted over in the #sustainability-team channel on the Drupal Slack, and @catch suggested there to repost it in this issue as well.

There is the following linting tool: https://github.com/ausi/respimagelint which provides recommendations about the used image sizes as well as the syntax of img srcset and the picture element. I wonder for a while now if it wouldn't be possible to adjust the algorithm of respimagelint to enable Drupal Core to auto generate a list of image styles for the installed default theme? For the default theme you know all the breakpoints across viewports and the syntax for img srcset and the picture elements, shouldn't it then be possible, instead of just optimizing image sizes, to auto generate a list of image styles from the ground up? But I am not a developer therefore i am uncertain if that might be a reasonable approach?

gaëlg’s picture

I just read about the Starshot project. This issue could be related?

catch’s picture

Yes I think so too, it would be a good thing to add alongside a theme builder.

I also opened #3446582: Responsive images recipe a couple of days ago, to ship some default image styles matching Olivero's break points to start with and linked this issue from there too.

andypost’s picture

andypost’s picture

would be great to start adoption of AVIF as it saving disk and bandwidth

catch’s picture

I think avif needs #3213491: Add fallback format support to responsive images unless it's already supported by all of Drupal's supported browsers.

mstrelan’s picture

@catch I think all supported browsers are covered. https://caniuse.com/avif

It's just older Safari and IE that aren't. Pretty sure even Firefox ESR is good as that is at version 115.

catch’s picture

Oh interesting I didn't realise browser support was so far ahead of PHP support.

I think the next thing to figure out would be how to add avif conversion to image styles by default, but only when it's available on the server.

Do we need a new conversion that does avif if available, but falls back to webp if it's not? We could then update install profiles (and Drupal CMS) to use that?

mstrelan’s picture

That sounds like a good idea. Actually I noticed Opera Mini is listed in our supported browsers and that doesn't support avif.

catch’s picture

So Opera Mini also doesn't support picture or sizes which means I think core's responsive image support already doesn't work with it, which would mean #3213491: Add fallback format support to responsive images also wouldn't work with it.

But also Opera Mini usage is dropping:

It doesn't show up on the global statcounter charts, so I checked Nigeria which came up via a google search as having some opera mini usage.

Opera Mini 4.4 usage is 2.76% in Nigeria in 2024-2025: https://gs.statcounter.com/browser-version-market-share/all/nigeria/#mon...

This is down from 3.49% for Opera Mini 4.4 and 1.49% for Opera Mini 7.4 in 2022-2023 https://gs.statcounter.com/browser-version-market-share/all/nigeria/#mon...

So that's usage about halved in two years.

Given that, I think we could at least open an issue to discuss dropping support for Opera Mini in Drupal 12, and do all the steps except making it the default image style action in the standard profile in Drupal 11.

catch’s picture

mstrelan’s picture

scott_euser’s picture

While AVIF is better for compression, I am finding it hard to come to a conclusion as to whether AVIF is a good recommendation vs WEBP purely from an environmental impact of power consumption perspective. I.e., the power needeed to compress/decompress WEBP seems to be compared to PNG, but all I can find is random blog posts without any quantitative analysis that keep saying AVIF compress/decompress is more expensive, outweighing the savings from reduced data transfer/bandwidth. I really find it hard to find anything conclusive though - has anyone else looked into it from that perspective?

Thanks!

andypost’s picture

AVIF is expensive (x2-x3 vs WEBP on compression) so fits for hires images mostly

catch’s picture

#3516434: Consider falling back to webp from AVIF based on filesize has a possible approach to the trade-offs between AVIF and webp for filesize.

gaëlg’s picture

Priority: Normal » Minor
Issue summary: View changes
Issue tags: -Needs subsystem maintainer review
mgifford’s picture

@scott_euser here is some reason comparisons between the two:

All three articles agree that AVIF’s superior compression leads to smaller image file sizes, which can reduce bandwidth usage and potentially lower energy consumption during data transmission. However, AVIF’s increased decoding time may require more processing power on the client side, possibly offsetting some energy savings.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

heddn’s picture