Skip to content

a6hijeet/drupal_avif_image_effect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Convert to AVIF / WebP (with fallback) — Drupal Image Effect

This custom Drupal image effect converts images to AVIF first, then falls back to WebP, and finally falls back to the original uploaded format if neither are supported by the image toolkit.

This was created for a real project where:

  • performance was important
  • we wanted AVIF first
  • WebP as fallback
  • and if both failed, images should still display (no broken images)

Drupal core allows AVIF conversion, but only with a single fallback.
This plugin adds an extra automatic fallback layer.


How it works

When the image effect runs:

  1. Try converting to AVIF
  2. If AVIF conversion is not supported or fails → try WebP
  3. If WebP is also unavailable → keep the original format

No broken images. No missing derivatives.


Requirements

  • Drupal 10 or Drupal 11

  • Image module enabled

  • Server must support at least one of:

    • avif
    • webp

(usually via GD or ImageMagick support)

If neither is supported, the original image format is used automatically.


Installation

Place the module here:

modules/custom/drupal_avif_image_effect

Enable the module:

drush en drupal_avif_image_effect -y

drush cr


Usage

  1. Go to:

    • Configuration → Media → Image styles
  2. Edit an existing image style (or create a new one)

  3. Add effect:

    • Convert to AVIF/WebP (with fallback)
  4. Save the image style

From now on, image derivatives will follow:

AVIF → WebP → Original

depending on toolkit support.


Simplified logic

if AVIF supported:

convert to avif

else if WebP supported:

convert to webp

else:

keep original

Why this module exists

Drupal core lets you:

  • convert to AVIF
  • choose one fallback format

But our requirement was:

AVIF → WebP → Original

The site had many images already uploaded, and editors were not manually optimizing formats.
This solution applies globally without requiring editors to change anything.


Troubleshooting

Images still appear as original format

This usually means:

  • your server does not support AVIF
  • and does not support WebP

In this case, fallback is working correctly.

Check status report:

/admin/reports/status

Look at image toolkit support.


About

Drupal module to automatically generate AVIF/WebP images with fallback for better performance and SEO

Topics

Resources

Stars

Watchers

Forks

Languages