No description
  • Rust 80.5%
  • Elixir 19.5%
Find a file
2023-11-17 11:17:31 -05:00
lib Docs 2023-11-17 11:02:10 -05:00
native/blurhash Generate the library 2023-11-16 15:19:57 -05:00
test Document the slight difference in results 2023-11-16 16:19:22 -05:00
.formatter.exs first commit 2023-11-16 13:56:56 -05:00
.gitignore Update gitignore 2023-11-16 14:07:29 -05:00
.tool-versions Pull in the Rust library unmodified 2023-11-16 14:07:17 -05:00
COPYING MIT 2023-11-17 10:33:43 -05:00
mix.exs Relax the Elixir version 2023-11-17 11:17:31 -05:00
mix.lock Pull in the Rust library unmodified 2023-11-16 14:07:17 -05:00
README.md README 2023-11-17 11:11:53 -05:00

Blurhash

Blurhash is an Elixir Rust NIF library based on the Rust implementation of Blurhash.

The library only exposes the ability to encode a blurhash at this time.

Usage

This library does not process image files. You are required to provide the raw data to Blurhash.encode/5.

The following is an example of using this library with Vix.

    {:ok, image} = Vix.Vips.Image.new_from_file(file)
    {height, width} = {Vix.Vips.Image.height(image), Vix.Vips.Image.width(image)}
    max = max(height, width)
    {x, y} = {max(round(width * 5 / max), 1), max(round(height * 5 / max), 1)}

    {:ok, rgba} =
      if Vix.Vips.Image.has_alpha?(image) do
        Vix.Vips.Image.to_list(image)
      else
        # Image has no alpha channel, so add one.
        Vix.Vips.Operation.bandjoin_const!(image, [255])
        |> Vix.Vips.Image.to_list()
      end

    rgba = List.flatten(rgba)

    Blurhash.encode(x, y, width, height, rgba)

Please note it is wasteful to make a blurhash of a large image, so you may want to resize it first.

Installation

If available in Hex, the package can be installed by adding blurhash to your list of dependencies in mix.exs:

def deps do
  [
    {:blurhash, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/blurhash.