A pure Crystal implementation of Blurhash. The API is stable, however the hashing function in either direction may not be.
Blurhash is an algorithm written by Dag Ågren for Wolt (woltapp/blurhash) that encodes an image into a short (~20-30 byte) ASCII string. When you decode the string back into an image, you get a gradient of colors that represent the original image. This can be useful for scenarios where you want an image placeholder before loading, or even to censor the contents of an image à la Mastodon.
Currently supports PNG
and JPEG
file types.
-
Add the dependency to your
shard.yml
:dependencies: blurhash: github: Sija/blurhash.cr
-
Run
shards install
- Run
shards build --release
require "blurhash"
puts Blurhash.encode(
x_components: 4,
y_components: 3,
path: Path["foo.png"]
)
$ ./bin/blurhash 4 3 foo.png
- Fork it (https://github.com/Sija/blurhash.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Sijawusz Pur Rahnama - creator and maintainer