All Projects → Raincal → blurhash-rs

Raincal / blurhash-rs

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
A pure Rust implementation of Blurhash

Programming Languages

rust
11053 projects
HCL
1544 projects

Labels

Projects that are alternatives of or similar to blurhash-rs

blurhash
A PHP implementation of BlurHash with Laravel integration.
Stars: ✭ 46 (+58.62%)
Mutual labels:  blurhash
blurhash-as
Blurhash implementation in AssemblyScript
Stars: ✭ 26 (-10.34%)
Mutual labels:  blurhash
blurhash.cr
A pure Crystal implementation of BlurHash algorithm
Stars: ✭ 13 (-55.17%)
Mutual labels:  blurhash

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].