Crates.io | blurhash |
lib.rs | blurhash |
version | 0.2.3 |
source | src |
created_at | 2019-07-12 11:30:11.138763 |
updated_at | 2024-07-23 10:43:37.067642 |
description | A pure Rust implementation of blurhash |
homepage | |
repository | https://github.com/whisperfish/blurhash-rs |
max_upload_size | |
id | 148466 |
size | 322,558 |
A pure Rust implementation of Blurhash.
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 a la Mastodon.
Add blurhash
to your Cargo.toml
:
[dependencies]
blurhash = "0.2.3"
By default, the fast-linear-to-srgb
is enabled.
This improves decoding performance by about 60%, but has a memory overhead of 8KB.
If this overhead is problematic, you can disable it by instead specifying the following to your Cargo.toml
:
[dependencies]
blurhash = { version = "0.2.3", default-features = false }
use blurhash::encode;
use image::GenericImageView;
fn main() {
// Add image to your Cargo.toml
let img = image::open("octocat.png").unwrap();
let (width, height) = img.dimensions();
let blurhash = encode(4, 3, width, height, &img.to_rgba().into_vec());
}
use blurhash::decode;
let pixels = decode("LBAdAqof00WCqZj[PDay0.WB}pof", 50, 50, 1.0);
Licensed under either of