-
Notifications
You must be signed in to change notification settings - Fork 13
Document the image feature flag, and converting to a base64 png. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
7b26d25
2ce30f7
661ecd5
d29ec31
7e787f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ blurhash = { version = "0.2.3", default-features = false } | |
| ``` | ||
|
|
||
| ### Encoding | ||
|
|
||
| ```rust | ||
| use blurhash::encode; | ||
| use image::GenericImageView; | ||
|
|
@@ -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: | ||
dessalines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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); | ||
| ``` | ||
|
|
||
|
||
| ## 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| //! ``` | ||
|
||
| //! [1]: https://github.com/woltapp/blurhash | ||
| mod ac; | ||
| mod base83; | ||
|
|
||
There was a problem hiding this comment.
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.