blurhash-ng

Crates.ioblurhash-ng
lib.rsblurhash-ng
version0.1.2
sourcesrc
created_at2021-11-05 14:02:34.51897
updated_at2021-11-05 14:02:34.51897
descriptionA pure Rust implementation of blurhash
homepage
repositoryhttps://github.com/Raincal/blurhash-rs
max_upload_size
id477335
size102,374
Zoë (duplexsystem)

documentation

https://docs.rs/blurhash

README

blurhash-rs

Crates.io Actions Status Crates.io

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.

🚴 Usage

Add blurhash to your Cargo.toml:

[dependencies]
blurhash = "0.1.1"

Encoding

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());
}

Decoding

use blurhash::decode;

let pixels = decode("LBAdAqof00WCqZj[PDay0.WB}pof", 50, 50, 1.0);

Licence

Licensed under either of

Commit count: 15

cargo fmt