It is easy to obtain a sub-image of a given image. We can use crop_imm to select a rectangular area and output the area as an image.
fn main() {
let img = image::open("my_image.jpg").unwrap();
let img2 = img.crop_imm(128, 128, 384, 640);
img2.save("crop.jpg").unwrap();
}
Original image:
crop.jpg:
➡️ Next: Resizing While Preserving Aspect Ratios
📘 Back: Table of contents