Documentation
¶
Overview ¶
Package blurhash provides encoding and decoding of Blurhash image placeholders.
Blurhash is an algorithm that encodes an image into a short ASCII string representing a gradient of colors. When decoded, this string produces a blurred placeholder that approximates the original image's colors and structure.
For simple one-off operations, use the package-level Encode and Decode functions. For batch processing with reduced allocations, use the reusable Encoder and Decoder types.
Index ¶
- Variables
- func Components(hash string) (x, y int, err error)
- func Decode(hash string, width, height int, punch int) (image.Image, error)
- func DecodeDraw(dst draw.Image, hash string, punch float64) error
- func Encode(xComponents, yComponents int, img image.Image) (string, error)
- type Decoder
- type Encoder
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidComponents is returned when components passed to Encode are invalid. ErrInvalidComponents = errors.New("blurhash: must have between 1 and 9 components") // ErrInvalidHash is returned when the library encounters a hash it can't recognise. ErrInvalidHash = errors.New("blurhash: invalid hash") // ErrInvalidDimensions is returned when width or height is invalid. ErrInvalidDimensions = errors.New("blurhash: width and height must be positive") )
Functions ¶
func Components ¶
Components returns the X and Y components of a blurhash.
func DecodeDraw ¶
DecodeDraw decodes the given hash into the given image.
Types ¶
type Decoder ¶ added in v1.2.0
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a reusable blurhash decoder that minimizes allocations by reusing internal buffers across decode operations.
A Decoder is safe for sequential use but not for concurrent use. For concurrent workloads, use a sync.Pool of Decoders.
The zero value is ready to use.
func NewDecoder ¶ added in v1.2.0
func NewDecoder() *Decoder
NewDecoder creates a new reusable Decoder. Buffers are allocated lazily on first use and grown as needed.
type Encoder ¶ added in v1.2.0
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a reusable blurhash encoder that minimizes allocations by reusing internal buffers across encode operations.
An Encoder is safe for sequential use but not for concurrent use. For concurrent workloads, use a sync.Pool of Encoders.
The zero value is ready to use.
func NewEncoder ¶ added in v1.2.0
func NewEncoder() *Encoder
NewEncoder creates a new reusable Encoder. Buffers are allocated lazily on first use and grown as needed.
