The Blurhash example

BlurHash is a compact representation of a placeholder for an image.

- https://blurha.sh/

Why would you want this?

Does your designer cry every time you load their beautifully designed screen, and it is full of empty boxes because all the images have not loaded yet? Does your database engineer cry when you want to solve this by trying to cram little thumbnail images into your data to show as placeholders?
BlurHash to the rescue!

Replace boring grey boxes with beautiful blurhash states and the designers will be happy. Blurhash strings are short enough to be added as a field in a JSON object and to be stored in a database. The implementations are small and easy to port to new languages, and the end result is a smooth and interesting experience for your users.

How does it work?

In short, BlurHash takes an image, and gives you a short string (only 20-30 characters!) that represents the placeholder for this image. You do this on the backend of your service, and store the string along with the image. When you send data to your client, you send both the URL to the image, and the BlurHash string. Your client then takes the string, and decodes it into an image that it shows while the real image is loading over the network. The string is short enough that it comfortably fits into whatever data format you use. For instance, it can easily be added as a field in a JSON object.

Blurhash illustration

This module adds a Blurhash to any image field, no configuration required.
See the README.md for installation instructions.

Installation
It is assumed you are installing Drupal through Composer using the Drupal
Composer facade. See https://www.drupal.org/docs/develop/using-composer/using-composer-to-man...

composer require wikimedia/composer-merge-plugin
composer require oomphinc/composer-installers-extender

Add the following to your composer.json file under "extra"

"merge-plugin": {
    "include": [
        "web/modules/contrib/blurhash/composer.libraries.json"
    ]
}

Then run

composer require drupal/blurhash

Logo icon by Solar Icons in CC Attribution License via SVG Repo

Project information

  • Created by johnwebdev on , updated
  • shieldStable releases for this project are covered by the security advisory policy.
    Look for the shield icon below.

Releases