BlurHash encoder and decoder in GO
This is basically a port of the Wolt TypeScript version of
the Blurhash alorithm implementation
At the moment works with png only
Usage as a library
Just import package using go get:
go get -u github.com/sergeysadov/blurhash
For encoding use:
img, err := utils.GetImg(componentX, componentY, path)
if err != nil {
//handle error
}
hash, _ := blurhash.Encode(img)
For decoding use:
pixels, err := blurhash.Decode(blurHash, width, height, 0)
if err != nil {
//handle error
}
nrgba := image.NewRGBA(image.Rect(0, 0, width, height))
nrgba.Pix = pixels
out, err := os.Create(resultPath)
if err != nil {
//handler error
}
defer out.Close()
if err := png.Encode(out, nrgba); err != nil {
//handle error
}
To build encoder use
$ make encoder
$ ./blurhash-encoder -xComponents 4 -yComponents 3 -path resources/pic.png
LaJR8MVu8_~po#smR+a~xaoLWCRj
To build decoder use
$ make decoder
$ ./blurhash-decoder -width 32 -height 32 -hash LaJR8MVu8_~po#smR+a~xaoLWCRj -result result.png
LaJR8MVu8_~po#smR+a~xaoLWCRj
TODO List
- Other image formats
- Benchmarks
- More unit tests
Licence
This project is licensed under the MIT License