No description
- Rust 80.5%
- Elixir 19.5%
| lib | ||
| native/blurhash | ||
| test | ||
| .formatter.exs | ||
| .gitignore | ||
| .tool-versions | ||
| COPYING | ||
| mix.exs | ||
| mix.lock | ||
| README.md | ||
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.