13 stable releases

Uses new Rust 2024

new 2.5.1 Mar 18, 2025
2.4.4 Mar 17, 2025
2.2.0 Feb 23, 2025
1.0.0 Jan 1, 2024
0.1.0 Jun 2, 2023

#109 in Images

Download history 38/week @ 2024-12-01 66/week @ 2024-12-08 19/week @ 2024-12-15 3/week @ 2024-12-22 33/week @ 2024-12-29 15/week @ 2025-01-05 251/week @ 2025-02-16 148/week @ 2025-02-23 726/week @ 2025-03-02 62/week @ 2025-03-09 251/week @ 2025-03-16

1,195 downloads per month

MIT license

98KB
2K SLoC

Photo

Utility image classes for Rust.

Features

  • Grayscale, Grascale with alpha, RGB and RGBA images, as well as custom color types.
  • Colour maps
  • Image IO
  • Image transformations utilities.
  • Tile manipulation.
  • Generic precision types for image components: u8, f32, f64 etc.
  • Print images to the console.

Usage

Reading and writing images

Loading a RGB image with f32 components:

use photo::ImageRGB;

let mut image = ImageRGB::<f32>::load("input/my_colour_image.png").expect("Failed to load image");

Save it:

image.save("output/my_colour_image.png").expect("Failed to save image");

Image transformations

image.flip_horizontal();
image.rotate_clockwise();

Tiling

let tile_size = (14, 14); // 14x14 pixel tiles
let tiles: Arrray2<ImageRGB> = image.tiles(tile_size);

Colour maps

let colours = vec!["#FF0000", "#00FF00", "#0000FF00"];
let colour_map: ColourMap<f32, LinSrgba> = ColourMap::new(&colours);

let sample = colour_map.sample(0.75);

Colourize grayscale images

use photo::ImageG;

let grayscale_image = ImageG::<u8>::load("input/my_grayscale_image.png").expect("Failed to load image");
let coloured_image = grayscale_image.colourize(&colour_map);

Print images to the console

println!("{}", image);

Dependencies

~6MB
~116K SLoC