How to serve WebP images with a Drupal 8/Drupal 9 site



Your web server needs to support WebP through PHP.
PHP 5 >= 5.4.0
GD Library

php -i | grep 'WebP'
WebP Support => enabled


This tutorial only works with Drupal 8/9. As a start you’ll need to enable/install some modules:

  1. ImageAPI Optimize WebP
    ⚠️ Make sure to enable the “ImageAPI Optimize WebP Responsive” submodule if you’re using the Responsive Image module in Drupal Core.
  2. ImageAPI Optimize Binaries
    This module is optional but it provides support for popular binary image processors like JpegOptim, PngQuant, AdvPNG etc.
Screenshot of the Modules overview where you can see the installed ImageAPI modules

Drupal Configuration

Head over to /admin/config/media/imageapi-optimize-pipelines for the Image API configuration.

The Image Optimize configuration page should look similar to this one. Note that you might only see the “Local Binaries” Pipeline first (if you installed it)

Let’s create a new pipeline

1. Add a new optimization pipeline
By clicking on “+ Add optimization pipeline”

Add optimization pipeline
fill in the name of your pipeline
Add new Processor, choose “WebP Deriver”

Sascha Eggenberger. Senior User Experience Designer @unic @Drupal Contributor. Drupal Design System, Claro, Gin. #OpenSource