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
Link to this section Functions
Decode a BlurHash string to RGB pixel data.
Parameters
blurhash: BlurHash stringwidth: Desired output widthheight: Desired output heightpunch: 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
Encode an image to a BlurHash string.
Parameters
pixels: List of RGB pixel values [r, g, b, r, g, b, ...]width: Image widthheight: Image heightx_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