#image #color

picto

Image handling library

14 releases

Uses new Rust 2021

0.4.4 Nov 30, 2021
0.4.3 Jan 28, 2017
0.4.2 Dec 22, 2016
0.4.0 Nov 2, 2016
0.1.2 Sep 25, 2016

#164 in Images

Download history 26/week @ 2022-03-09 52/week @ 2022-03-16 48/week @ 2022-03-23 12/week @ 2022-03-30 11/week @ 2022-04-06 17/week @ 2022-04-13 9/week @ 2022-04-20 107/week @ 2022-04-27 95/week @ 2022-05-04 222/week @ 2022-05-11 72/week @ 2022-05-18 70/week @ 2022-05-25 113/week @ 2022-06-01 36/week @ 2022-06-08 15/week @ 2022-06-15 29/week @ 2022-06-22

194 downloads per month
Used in 2 crates

WTFPL license

225KB
8K SLoC

picto

Crates.io Crates.io WTFPL Build Status

An image handling library.

Usage

Add the following to the Cargo.toml in your project:

[dependencies]
picto = "0.2"

Supported Formats

Format Decoding Encoding
PNG
JPEG
GIF
BMP
TGA
XYZ

Documentation

Documentation is available here.

Example

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();
}

sRGB and friends

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());

Dependencies

~3MB
~52K SLoC