Feature request: Blur-hash

I’m using blurred images in my site, mostly for filling background in different aspect ratio, but others use it for previews as well. I’m currently doing manual blurs by defining a very small derivation (5x5 in most cases), like

  derivation :blur do |file, width, height|
      .resize_to_limit(width.to_i, height.to_i)
      .saver(optimize_coding: true, strip: true, q: 1)

The obvious disadvantages are creating many small files and, even worse, delivering many small files to browsers.

I recently stumbled over https://blurha.sh/ (github: https://github.com/woltapp/blurhash) and considered moving to that. Is there something already available, e.g. as a plugin, or do I need to roll my own? I considered adding the blur-hash string as metadata field and outputting that directly to HTML. Do you have a better idea how to integrate it better?

Sounds like a cool feature to have, I’m not aware of existing solutions for this. Yeah, the way you described it sounds like a good way to go.

If you manage to get this working, it would be great if you could add a “How to” guide on the Shrine wiki.

I am also looking at doing something similar.

There is a Ruby Blurhash implementation, but it needs an array of every pixel.

Here are examples on using it with Rmagick, minimagick & vips: https://github.com/Gargron/blurhash/issues/7

It allocates a Ruby array with every pixel so it is not very performant. You can run it against a resized image so you work on fewer pixels, but this is still not very optimized.

I will try to get an optimised Vips implementation, I am looking for a bit of guidance: https://github.com/libvips/ruby-vips/issues/235

The overall goal here would be to have a Shrine plugin adding a blurhash metadata, supporting various implementations and allowing you to specify options. I do not have the time available right now for this, but I will have a look in the coming weeks.

If you already have something working, I would like to have a loot at it and help you!

I started working on the plugin here: https://github.com/renchap/shrine-blurhash

I took inspiration from Shrine’s built-in store_dimensions plugin.

It currently does not does much but I should have a first working version soon!


I pushed a first working version. It only support ruby-vips for now.
I created issues in the repository for the feature I intend to implement, feel free to chime in and add your, or send a PR if you have time :slight_smile:

I expect to release the first version in the coming 2 weeks.

First version released: https://github.com/renchap/shrine-blurhash

I will stop spamming here now, please open issues on the repository as needed!

1 Like

Hi Renaud, this looks great. Thanks a lot!
I’m currently on other projects but I’m looking very much forward at integrating your implementation.