Pure Elixir implementation of Blurhash algorithm with no additional dependencies.
Blurhash is an algorithm by Dag Ågren of Wolt that decodes an image to a very compact (~ 20-30 bytes) ASCII string representation, which can be then decoded into a blurred placeholder image. See the main repository for the rationale and details.
This library supports only encoding.
More details on https://blurha.sh/
Documentation available on hexdocs: https://hexdocs.pm/blurhash
BlurHash is published on Hex. Add it to your list of dependencies in mix.exs:
def deps do
[
{:blurhash, "~> 1.0.0"}
]
end
# Pixel data supplied in RGB order, with 3 bytes per pixels.
pixels = [255, 43, 20, 11, 0, 155, ...]
hash = BlurHash.encode(pixels, 30, 30, 4, 3)
IO.inspect(hash) # "LEHV6nWB2yk8pyo0adR*.7kCMdnj"
If you would like to convert raw binary instead of RGB image format, you can use eg Mogrify package to perform conversion.
import Mogrify
file =
open(path)
|> format("rgb")
|> save()
pixels =
File.read!(file.path)
|> :binary.bin_to_list()
hash = BlurHash.encode(pixels, 30, 30, 4, 3)
IO.inspect(hash) # "LEHV6nWB2yk8pyo0adR*.7kCMdnj"
Any contributions you make are greatly appreciated 🤓.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
Project Link: https://github.com/perzanko/blurhash-elixir