4 releases

0.2.1 Feb 26, 2024
0.2.0 Sep 19, 2023
0.1.1 Jul 12, 2019
0.1.0 Jul 12, 2019

#129 in Algorithms

Download history 1256/week @ 2023-12-23 944/week @ 2023-12-30 1267/week @ 2024-01-06 887/week @ 2024-01-13 1615/week @ 2024-01-20 1348/week @ 2024-01-27 1095/week @ 2024-02-03 1537/week @ 2024-02-10 1541/week @ 2024-02-17 1992/week @ 2024-02-24 1159/week @ 2024-03-02 1355/week @ 2024-03-09 1571/week @ 2024-03-16 1148/week @ 2024-03-23 1356/week @ 2024-03-30 1239/week @ 2024-04-06

5,550 downloads per month
Used in 5 crates (4 directly)

Apache-2.0/MIT

265KB
470 lines

blurhash-rs

CI Build Crates.io 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.2.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

Dependencies

~0–12MB
~82K SLoC