Skip to content

Latest commit

 

History

History
35 lines (22 loc) · 1.21 KB

resizing_while_preserving_aspect_ratios.md

File metadata and controls

35 lines (22 loc) · 1.21 KB

Resizing While Preserving Aspect Ratios

The library provides a few methods for resizing images. To resize an image while the aspect ratio is preserved, we can use resize.

use image::imageops::FilterType;

fn main() {
    let img = image::open("my_image.jpg").unwrap();
    
    let img2 = img.resize(100, 100, FilterType::Triangle);
    img2.save("resize.jpg").unwrap();
}

Original image:

my_image

resize.jpg:

resize

Although we specify a square as the new image size, the method adjusts the width and height automatically to a suitable size.

In addition to FilterType::Triangle, there are five filters. Readers interested in the filters may refer to the document for their effects.

The example scales down the image. But one could scale up an image to make it bigger.

➡️ Next: Resizing Without Preserving Aspect Ratios

📘 Back: Table of contents