Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions README.md
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran prettier on this file also.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ blurhash = { version = "0.2.3", default-features = false }
```

### Encoding

```rust
use blurhash::encode;
use image::GenericImageView;
Expand All @@ -40,15 +41,36 @@ fn main() {
```

### Decoding

```rust
use blurhash::decode;

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

To decode into an `ImageBuffer`, add the `image` feature flag, then do:

```rust
use blurhash::decode_image;

let image_buffer = decode_image(blurhash, width, height, 1.0).unwrap();
```

If you'd like to convert this image to a base64 `png`, you can add the `base64` and `image` crates, then do:

```rust
use base64::{engine::general_purpose, Engine as _};
use std::io::Cursor;

let mut bytes: Vec<u8> = Vec::new();
image_buffer.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png).unwrap();

let b64_png = general_purpose::STANDARD.encode(bytes);
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't include this. The whole purpose of blurhash is to have a succinct representation of an image, and this method does the exact opposite: it decodes our succinct representation into an image, then recompresses as a png, and then blows up the file through base64.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, removed that block now.

## Licence

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
//!
//! let pixels = decode("LBAdAqof00WCqZj[PDay0.WB}pof", 50, 50, 1.0);
//! ```
//!
//! To decode into an `ImageBuffer`, add the `image` feature flag, then do:
//!
//! ```no_run
//! use blurhash::decode_image;
//!
//! let image_buffer = decode_image(blurhash, width, height, 1.0).unwrap();
//! ```
//!
//! If you'd like to convert this image to a base64 `png`, you can add the `base64` and `image` crates, then do:
//!
//! ```no_run
//! use base64::{engine::general_purpose, Engine as _};
//! use std::io::Cursor;
//!
//! let mut bytes: Vec<u8> = Vec::new();
//! image_buffer.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png).unwrap();
//!
//! let b64_png = general_purpose::STANDARD.encode(bytes);
//! ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This is not an approach I want to recommend to users of this crate.

//! [1]: https://github.com/woltapp/blurhash
mod ac;
mod base83;
Expand Down