BlurHash v2.0.0 BlurHash View Source

BlurHash implementation in Elixir.

BlurHash is a compact representation of a placeholder for an image. It applies a DCT transform to the image data and encodes the components using a base 83 encoding.

Examples

iex> pixels = BlurHash.decode("LlMF%n00%#MwS|WCWEM{R*bbWBbH", 4, 3)
iex> length(pixels)
36
iex> Enum.all?(pixels, fn x -> x >= 0 and x <= 255 end)
true

Link to this section Summary

Functions

Decode a BlurHash string to RGB pixel data.

Encode an image to a BlurHash string.

Link to this section Functions

Link to this function

decode(blurhash, width, height, punch \\ 1.0)

View Source

Decode a BlurHash string to RGB pixel data.

Parameters

  • blurhash: BlurHash string
  • width: Desired output width
  • height: Desired output height
  • punch: Contrast adjustment (default: 1.0)

Returns

List of RGB pixel values [r, g, b, r, g, b, ...]

Examples

iex> pixels = BlurHash.decode("LlMF%n00%#MwS|WCWEM{R*bbWBbH", 4, 3)
iex> length(pixels)
36
iex> Enum.all?(pixels, fn x -> x >= 0 and x <= 255 end)
true
Link to this function

encode(pixels, width, height, x_components, y_components)

View Source

Encode an image to a BlurHash string.

Parameters

  • pixels: List of RGB pixel values [r, g, b, r, g, b, ...]
  • width: Image width
  • height: Image height
  • x_components: Number of components along X axis (1-9)
  • y_components: Number of components along Y axis (1-9)

Returns

BlurHash string

Examples

iex> pixels = [255, 0, 0, 0, 255, 0, 0, 0, 255]
iex> blurhash = BlurHash.encode(pixels, 3, 1, 4, 3)
iex> is_binary(blurhash)
true
iex> String.length(blurhash) > 6
true