No description
Find a file
2020-05-14 10:58:42 +03:00
src Support all colormodes 2020-05-14 10:57:21 +03:00
tests Version 0.2.0. Adapt to imageman changes. decode requires target colormode. 2019-07-31 10:06:10 +03:00
.gitignore Initial implementation 2019-07-26 15:38:23 +03:00
blurhash.nimble Version 0.2.1 2020-05-14 10:58:42 +03:00
LICENSE Initial implementation 2019-07-26 15:38:23 +03:00
README.md Fix example in readme 2020-05-14 10:56:52 +03:00

blurhash

Pure Nim implementation of Blurhash

Blurhash is an algorithm written by Dag Ågren for Wolt (woltapp/blurhash) that encodes an image into a short (~20-30 byte) ASCII string. When you decode the string back into an image, you get a gradient of colors that represent the original image. This can be useful for scenarios where you want an image placeholder before loading, or even to censor the contents of an image a la Mastodon.

Installation

nimble install blurhash

Usage

Add requires "blurhash" to your .nimble file.

Encoding

import blurhash, imageman/[images, colors]

let
  image = loadImage[ColorRGB]("image.png")
  hash = image.encode(5, 5)

echo hash

This snippet hashes following image into this compact string: UrQ]$mfQ~qj@ocofWFWB?bj[D%azf6WBj[t7

reference_image

Decoding

import blurhash, imageman/images

let image = "UrQ]$mfQ~qj@ocofWFWB?bj[D%azf6WBj[t7".decode[ColorRGBU](500, 500)

image.savePNG "blurred.png"

This results in following image:

blurred_image

Other

Reference image author - https://rigani.me