[][src]Function raster::editor::crop

pub fn crop(
    src: &mut Image,
    crop_width: i32,
    crop_height: i32,
    position: PositionMode,
    offset_x: i32,
    offset_y: i32
) -> RasterResult<()>

Crop the image to the given dimension and position.

The offset_x and offset_y are added to the final position. Can also be negative offsets. Offsets can be used to nudge the final position. Or you can set the position to PositionMode::TopLeft and use the offsets as a normal screen x and y coordinates.

Examples

Input

Code

use raster::{editor, PositionMode};

// Create image from file
let mut top_left = raster::open("tests/in/crop-test.jpg").unwrap();

// Make copies
let mut top_center = top_left.clone();
let mut top_right = top_left.clone();

let mut center_left = top_left.clone();
let mut center = top_left.clone();
let mut center_right = top_left.clone();

let mut bottom_left = top_left.clone();
let mut bottom_center = top_left.clone();
let mut bottom_right = top_left.clone();

// Crop it
editor::crop(&mut top_left, 167, 93, PositionMode::TopLeft, 0, 0).unwrap();
editor::crop(&mut top_center, 166, 93, PositionMode::TopCenter, 0, 0).unwrap();
editor::crop(&mut top_right, 167, 93, PositionMode::TopRight, 0, 0).unwrap();

editor::crop(&mut center_left, 167, 93, PositionMode::CenterLeft, 0, 0).unwrap();
editor::crop(&mut center, 166, 93, PositionMode::Center, 0, 0).unwrap();
editor::crop(&mut center_right, 167, 93, PositionMode::CenterRight, 0, 0).unwrap();

editor::crop(&mut bottom_left, 167, 93, PositionMode::BottomLeft, 0, 0).unwrap();
editor::crop(&mut bottom_center, 166, 93, PositionMode::BottomCenter, 0, 0).unwrap();
editor::crop(&mut bottom_right, 167, 93, PositionMode::BottomRight, 0, 0).unwrap();

// Save it
raster::save(&top_left, "tests/out/test_crop_top_left.jpg").unwrap();
raster::save(&top_center, "tests/out/test_crop_top_center.jpg").unwrap();
raster::save(&top_right, "tests/out/test_crop_top_right.jpg").unwrap();

raster::save(&center_left, "tests/out/test_crop_center_left.jpg").unwrap();
raster::save(&center, "tests/out/test_crop_center.jpg").unwrap();
raster::save(&center_right, "tests/out/test_crop_center_right.jpg").unwrap();

raster::save(&bottom_left, "tests/out/test_crop_bottom_left.jpg").unwrap();
raster::save(&bottom_center, "tests/out/test_crop_bottom_center.jpg").unwrap();
raster::save(&bottom_right, "tests/out/test_crop_bottom_right.jpg").unwrap();

Output

The cropped images arranged in a grid, showing how you can easily set the crop position.