Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sija/blurhash.cr
A pure Crystal implementation of BlurHash algorithm
https://github.com/sija/blurhash.cr
blurhash crystal image placeholder
Last synced: 11 days ago
JSON representation
A pure Crystal implementation of BlurHash algorithm
- Host: GitHub
- URL: https://github.com/sija/blurhash.cr
- Owner: Sija
- License: mit
- Created: 2020-02-26T17:15:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T00:42:45.000Z (8 months ago)
- Last Synced: 2024-10-25T01:58:38.322Z (19 days ago)
- Topics: blurhash, crystal, image, placeholder
- Language: Crystal
- Homepage:
- Size: 228 KB
- Stars: 23
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# blurhash.cr [![CI](https://github.com/Sija/blurhash.cr/actions/workflows/ci.yml/badge.svg)](https://github.com/Sija/blurhash.cr/actions/workflows/ci.yml) [![Releases](https://img.shields.io/github/release/Sija/blurhash.cr.svg)](https://github.com/Sija/blurhash.cr/releases) [![License](https://img.shields.io/github/license/Sija/blurhash.cr.svg)](https://github.com/Sija/blurhash.cr/blob/master/LICENSE)
A pure Crystal implementation of [Blurhash](https://github.com/woltapp/blurhash). The API is stable, however the hashing function in either direction may not be.
Blurhash is an algorithm written by [Dag Ågren](https://github.com/DagAgren) for [Wolt (woltapp/blurhash)](https://github.com/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](https://blog.joinmastodon.org/2019/05/improving-support-for-adult-content-on-mastodon/).
Currently supports `PNG` and `JPEG` file types.
## Installation
### Library
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
blurhash:
github: Sija/blurhash.cr
```2. Run `shards install`
### CLI
1. Run `shards build --release`
## Usage
### Library
```crystal
require "blurhash"puts Blurhash.encode(
x_components: 4,
y_components: 3,
path: Path["foo.png"]
)
```### CLI
```console
$ ./bin/blurhash 4 3 foo.png
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Sijawusz Pur Rahnama](https://github.com/Sija) - creator and maintainer