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.
nimble install blurhash
requires "blurhash" to your
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:
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:
Reference image author - https://rigani.me