Skip to content

SolitudeSF/blurhash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Blurhash encoder/decoder algorithm implemenation in Nim.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages