blurhash

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 7 Imported by: 12

README

go-blurhash Go Reference GitHub tag license Go Report Card codecov

A pure Go implementation of Blurhash. The API is stable, however the hashing function in either direction may not be.

Blurhash Demo

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.

Under the covers, this library is almost a straight port of the C version, which is known to encode images slightly differently than the TypeScript implementation.

Contributing

Issues, feature requests or improvements welcome!

Licence

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidComponents = errors.New("blurhash: must have between 1 and 9 components")

ErrInvalidComponents is returned when components passed to Encode are invalid.

View Source
var ErrInvalidHash = errors.New("blurhash: invalid hash")

ErrInvalidHash is returned when the library encounters a hash it can't recognise.

Functions

func Components

func Components(hash string) (x, y int, err error)

Components returns the X and Y components of a blurhash.

func Decode

func Decode(hash string, width, height int, punch int) (image.Image, error)

Decode returns an NRGBA image of the given hash with the given size.

func DecodeDraw

func DecodeDraw(dst draw.Image, hash string, punch float64) error

DecodeDraw decodes the given hash into the given image.

func Encode

func Encode(xComponents, yComponents int, img image.Image) (hash string, err error)

Encode returns the blurhash for the given image.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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