Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

This module enhances Drupal's responsive image functionality by allowing images to adapt to the size of their containing element, rather than the browser viewport. This is particularly useful for layouts created with tools like Layout Builder, where the structure of the page determines the image's display size. The module introduces a new image style formatter that uses container queries to select the appropriate image sizes.

This module extends the capabilities of the Core's Responsive Image by adding the ability to react to the size of the container (DOM element) in which the image is displayed, rather than the size of the view-port.
This approach is best suited to page construction based on the Layout Builder like in Sobki or Drupal "starshot" CMS, because it is the structuring of the section that determines the size of the containers.

Features

The module provides:

  • a breakpoint group "Container Queries Responsive Images", based on Core's "Responsive Image"
  • a "Container Queries Responsive Images" formatter for image fields which is designed to use only the responsive image styles using the provided breakpoint.

These elements are to be used in the same way as the classic responsive image style, with the exception that we only focus on the size of the container and no longer on the size of the window (view-port/media).

Installation requirements

See installation instructions.

Configuration

You can now use the "Container Queries Responsive Images" breakpoint in your responsive image styles.

Configure this breakpoint like with the "Responsive Image" breakpoint from Core.

Then on your image fields, use the new "Container queries responsive image" formatter and select one responsive image style using the new breakpoint.

Technical Notes

This module is based on a JavaScript script (in active development too) that attempts to enable "picture" tags to be used not in "media" mode but with a "container" mode.

How picture element work:

<picture>
  <source srcset="/path/to/img/size1.png 1x"
          media="(min-width: 1000px)"
          type="image/png" width="300" height="300">
  <source srcset="/path/to/img/size2.png 1x"
          media="(min-width: 500px)"
          type="image/png" width="100" height="100">
  <img loading="lazy" src="/path/to/img/default.png"
       width="300" height="300" alt="default_image">
</picture>

In this case, the image is selected according to the view-port (page width) and not the block containing the image.

What we are trying to make:

<picture>
  <source srcset="/path/to/img/size1.png 1x"
          container="(min-width: 300px)"
          type="image/png" width="300" height="300">
  <source srcset="/path/to/img/size2.png 1x"
          container="(min-width: 100px)"
          type="image/png" width="100" height="100">
  <img loading="lazy" src="/path/to/img/default.png"
       width="300" height="300" alt="default_image">
</picture>

In this approach, it is no longer the size of the view-port that defines the size of the image, but rather the block that restricts it.

The mechanism is reversed: it's the size of the frame that selects the image to be displayed.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
1.0.0-alpha2 Pre-release 10–11 Jan 8, 2025
1.0.0-alpha1 Pre-release 10–11 Dec 12, 2024
1.0.x-dev Dev 10–11 Nov 20, 2024