Crate raster [−] [src]
Raster
Raster is an image processing lib for Rust.
It provides a simplified API for processing raster images (JPEG, PNG and GIF).
Installation
Add this to your Cargo.toml file:
[dependencies] raster = "0.x.x"
Where x are version numbers of the latest version of raster. Eg.: 0.2.1
Then add the raster crate in your main.rs:
extern crate raster; // In your main rust file
Creating Images
From an image file
// Create an image from file let image = raster::open("tests/in/sample.png").unwrap();
Raster will detect the image format based on the file name.
Create a blank image
use raster::Image; // Include the Image struct // Create a blank 150x100 image. Defaults to a black background. let image = Image::blank(150, 100);
Saving Images
Save the opened image file:
// Create an image from file let image = raster::open("tests/in/sample.png").unwrap(); // Save opened image raster::save(&image, "tests/out/test_open_save.png");
Save the blank image:
use raster::Image; // Include the Image struct // Create a blank 150x100 image. Defaults to a black background. let image = Image::blank(150, 100); // Save blank raster::save(&image, "tests/out/test_blank.png");
A blank image:
Editing Images
use raster::editor; // Create an image from file let mut image = raster::open("tests/in/sample.png").unwrap(); // Resize an image to fit in a 200x200 box editor::resize(&mut image, 200, 200, "fit").unwrap(); // Save it raster::save(&image, "tests/out/test_resize_fit.png");
Blending 2 Images
use raster::editor; // Create images from file let image1 = raster::open("tests/in/sample.jpg").unwrap(); let image2 = raster::open("tests/in/watermark.png").unwrap(); // Blend image2 on top of image1 using normal mode, opacity of 1.0 (100%), with image2 at the center, with 0 x and 0 y offsets. whew let image3 = editor::blend(&image1, &image2, "normal", 1.0, "center", 0, 0).unwrap(); // Save it raster::save(&image3, "tests/out/test_blend_normal.png");
See the modules for more info.
Modules
compare |
A module for comparing images. |
editor |
A module for common image editing operations. |
filter |
A module for filtering pixels. |
interpolate |
A module for interpolating pixels. |
transform |
A module for 2D transformation. |
Structs
Color |
A struct for representing and creating color. |
Image |
A struct for easily representing a raster image. |
Functions
open |
Create an image from an image file. |
save |
Save an image to an image file. The image type is detected from the file extension of the file name. |