blurhash

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2021 License: MIT

README

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
}

Usage as a tool

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

Directories

Path Synopsis
cmd
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL