Liking cljdoc? Tell your friends :D

Blurhash

A Clojure implementation of Blurhash.

Blurhash is an algorithm by Dag Ågren of Wolt that decodes an image to a very compact (~ 20-30 bytes) ASCII string representation, which can be then decoded into a blurred placeholder image. See the main repo for the rationale and details.

Usage

The encode->hash->decode cycle looks something like this:

a cute hedgehog

UIGuXeS@x[xX_MORbuoy?uNGM{nTNHMzIVnn

essence of a cute hedgehog

The Clojure implementation is written in CLJC files, so that they can be used from Clojure and ClojureScript code alike.

Encoding

You can encode an image to a blurhash using the function blurhash.encode/encode. It takes an image as an RGB matrix, currently represented as nested native vectors. The blurhash.core namespace contains (Clojure-specific) functions to convert an image file into a matrix, so you can do something like this:

(ns my-namespace
  (:require [blurhash.core :refer [file->pixels]
            [blurhash.encode :refer [encode]]]))
(def image
  (file->pixels "./resources/example.jpg"))

(encode image)
=> "UIGuXeS@x[xX_MORbuoy?uNGM{nTNHMzIVnn"

Decoding

Here's an example of how to decode a blurhash into a placeholder image:

(ns my-namespace
  (:require [blurhash.core :refer [pixels->file]
            [blurhash.decode :refer [decode]]]))

(def blurred-image
  (decode "UIGuXeS@x[xX_MORbuoy?uNGM{nTNHMzIVnn" 300 236))

(pixels->file blurred-image "blurred-image.jpg")

TODO

Publish in Clojars.

License

Released under the MIT license.

Can you improve this documentation? These fine people already did:
Tuomo Virolainen & Esko Suomi
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close