Crates.io | picto |
lib.rs | picto |
version | 0.4.4 |
source | src |
created_at | 2016-09-21 16:49:03.65265 |
updated_at | 2021-11-30 12:59:33.03017 |
description | Image handling library. |
homepage | |
repository | https://github.com/meh/rust-picto |
max_upload_size | |
id | 6573 |
size | 1,166,883 |
An image handling library.
Add the following to the Cargo.toml
in your project:
[dependencies]
picto = "0.2"
Format | Decoding | Encoding |
---|---|---|
PNG | ✔ | ✔ |
JPEG | ✔ | ✘ |
GIF | ✔ | ✔ |
BMP | ✔ | ✔ |
TGA | ✔ | ✔ |
XYZ | ✔ | ✘ |
Documentation is available here.
The following example turns an image to gray scale (maintaining the alpha), then upscales it, and blurs it.
extern crate picto;
use picto::{read, write};
use picto::color::{Rgba, Lumaa};
use picto::processing::prelude::*;
use std::env;
fn main() {
write::to_path(env::args().nth(2).unwrap(),
&read::from_path::<u8, Rgba, _>(env::args().nth(1).unwrap()).unwrap()
.convert::<u8, Lumaa>()
.scale_by::<scaler::Cubic, u8, Rgba>(2.0)
.blur::<u8, Rgba>(4.0)).unwrap();
}
The RGB types and operations provided by picto assume the colors are given in linear RGB space, but many images contain the data in sRGB color space, this means some conversion needs to happen to have accurate operations.
The following code will load an image, and convert it to a Buffer
usable from
an sRGB space.
use picto;
use picto::color::{Rgb, Srgb};
let image = picto::read::from_path::<Rgb, u8, _>("path-to-image.jpg")
.convert_with::<Rgb, f32, _>(|p| Srgb::new(p.red, p.green, p.blue).into());