3 unstable releases

0.3.1 Oct 23, 2024
0.3.0 Jul 31, 2024
0.2.0 Jul 31, 2024

#238 in Images

Download history 3/week @ 2024-08-10 1/week @ 2024-08-17 1/week @ 2024-09-07 37/week @ 2024-09-14 39/week @ 2024-09-21 48/week @ 2024-09-28 6/week @ 2024-10-05 1/week @ 2024-10-12 141/week @ 2024-10-19 32/week @ 2024-10-26 12/week @ 2024-11-02 61/week @ 2024-11-09 3/week @ 2024-11-16 1/week @ 2024-11-23

81 downloads per month
Used in 2 crates (via rustypipe-downloader)

MIT license

37KB
1K SLoC

smartcrop.rs

Current crates.io version License CI status

Smartcrop is a content-aware image cropping library that attempts to find the best crop for a given image and aspect ratio.

The original Javascript implementation smartcrop.js was developed by Jonas Wagner.

This is a fork of https://github.com/bekh6ex/smartcrop.rs by Bekh-Ivanov Aleksey, since the original project is unmaintained and does not support newer versions of the image crate.

How to use

let height = 1920;
let width = 1080;

let res = smartcrop::find_best_crop(
    &image,
    NonZeroU32::new(height).unwrap(),
    NonZeroU32::new(width).unwrap()
).expect("Failed to find crop");
let c = res.crop;
let cropped = image.crop_imm(c.x, c.y, c.width, c.height);
let scaled = cropped.resize(width, height, image::imageops::FilterType::Lanczos3);

Dependencies

~1.5MB
~30K SLoC