https://github.com/perzanko/blurhash-elixir
Pure Elixir implementation of Blurhash algorithm with no additional dependencies.
https://github.com/perzanko/blurhash-elixir
blurhash elixir encoder
Last synced: 4 months ago
JSON representation
Pure Elixir implementation of Blurhash algorithm with no additional dependencies.
- Host: GitHub
- URL: https://github.com/perzanko/blurhash-elixir
- Owner: perzanko
- License: mit
- Created: 2020-08-18T19:10:21.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-07-25T11:10:21.000Z (11 months ago)
- Last Synced: 2025-10-31T22:04:34.039Z (8 months ago)
- Topics: blurhash, elixir, encoder
- Language: Elixir
- Homepage: https://hexdocs.pm/blurhash
- Size: 19.5 KB
- Stars: 40
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# BlurHash
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](https://github.com/woltapp/blurhash) for the rationale and details.
More details on https://blurha.sh/
Documentation available on hexdocs: https://hexdocs.pm/blurhash
## Installation
BlurHash is published on [Hex](https://hexdocs.pm/blurhash). Add it to your list of dependencies in mix.exs:
```elixir
def deps do
[
{:blurhash, "~> 2.0.0"}
]
end
```
## Usage
```elixir
# 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](https://github.com/route/mogrify) package to perform conversion.
```elixir
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"
```
## Contributing
Any contributions you make are **greatly appreciated** 🤓.
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## License
Distributed under the MIT License. See `LICENSE.md` for more information.
## Contact
[**@perzanko**](mailto:perzankowski.kacper@gmail.com)
---
Project Link: [https://github.com/perzanko/blurhash-elixir](https://github.com/perzanko/blurhash-elixir)