Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Image Styles Builder

107 sites Security covered
View on drupal.org

This module allows developers to quickly create multiple Drupal image styles in bulk by defining them in YAML files. It can generate styles from definitions, roll them back, and even fetch defined styles in Twig templates.

Image Styles Builder allows a developer to quickly create image styles in bulk, based on definition files.

The goal of this package is to enable the rapid creation of image styles by declaring them in a custom module file definition (YAML).

The primary aim of Image Styles Builder is to allow Frontend to declare many necessary image-styles and provide to Backend
developers a way to document and define those styles to be generated or flushed at any moment.

Use Image Styles Builder if

  • You need to generate Drupal Images Styles quickly without using the UI
  • You receive a definition/lists of Images Styles to generate from another co-worker/team
  • You have a lot of Images Styles to generate at once
  • You want to be able to generate Images Styles and Rollback them easily
  • You want to be able to fetch a collection of Image Styles in Twig (must previously be defined with this module)

Getting Started

We highly recommend you to install the module using `composer` as a dev dependency.

Caution, If you desire to use the Twig Filter on production, then install the module a s root dependency instead of dev dependency.

composer require --dev drupal/image_styles_builder

Usage

Generating & Rollback of Image Styles

  1. Create your own custom module that will contain your image styles definition(s).
  2. Create your derivative definition file yourmodule.image_styles_builder_derivatives.yml:
    default:
      id: default
      label: Default
      suffix: dft
      styles:
        9_2_64x14:
          effects:
            -
              type: 'scale_and_crop'
              data:
                width: 64
                height: 14
        9_2_640x142:
          effects:
            -
              type: 'scale_and_crop'
              data:
                width: 640
                height: 142
        9_2_640x142_webp:
          effects:
            -
              type: 'scale_and_crop'
              data:
                width: 640
                height: 142
            -
              type: 'image_convert'
              data:
                extension: 'webp'
        16_10_64x40:
          effects:
            -
              type: 'scale_and_crop'
              data:
                width: 64
                height: 40
        16_10_128x80:
          effects:
            -
              type: 'scale_and_crop'
              data:
                width: 128
                height: 80
            -
              type: 'image_scale'
              data:
                width: 64
        original_64:
          effects:
            -
              type: 'image_scale'
              data:
                width: 64
    
  3. Run the generate command to build your image styles in bulk.
    drush isb:gen
    
  4. (optional) Export the new image styles configuration.
  5. (optional) Rollback previously generated Image styles with the flush command.
    drush isb:flush
    

Fetch Image Styles in Twig

Once generated, you may want to fetch your image styles by definition. This is possible throughout the isb_image_styles Twig function.

Twig Example code

{% styles = isb_image_styles('default') %}
{{ styles|json_encode }}

Caution, If you desire to use the Twig Filter on production, then install the module a s root dependency instead of dev dependency.

Exposed Drush Commands

This module is shipped with drush commands to assist you in your workflow.

Generate Command

The Generate command will create new image styles (and skip existing ones) by discovering all the derivatives files (*.image_styles_builder_derivatives.yml)

drush isb:gen

Flush Command

The Flush command will delete every image styles that have been created during a previous isb:gen.
The discovery operation will be based on all the derivatives files (*.image_styles_builder_derivatives.yml):

drush isb:flush

Versions

Drupal Core Image Styles Builder 8.x none 9.x 1.0.x 10.x 1.1.x 11.x 1.1.x

Dependencies

The Drupal 9, Drupal 10 & Drupal 11 version of Image Styles Builder requires nothing !
Feel free to use it.

Image Styles Builder requires PHP 7.4+ to works properly. We recommend updating to at least
PHP 8.1 if possible, and ideally PHP 8.2, which is supported as of Drupal 10.x.

Similar modules

  • Image Style Generate allows a site administrator to quickly create image styles in bulk, based on a defined set of rules and patterns.

Supporting organizations

This project is sponsored by Antistatique. We are a Swiss Web Agency, Visit us at www.antistatique.net or Contact us.

Activity

Total releases
5
First release
Apr 2025
Latest release
2 months ago
Releases (12 mo)
3 ▲ from 2
Maintenance
Active

Release Timeline

Releases

Version Type Release date
1.1.7 Stable Apr 28, 2026
1.1.6 Stable Jan 26, 2026
1.1.5 Stable Nov 7, 2025
1.1.4 Stable Jun 3, 2025
1.1.3 Stable Apr 23, 2025