| Crates.io | smartcrop2 |
| lib.rs | smartcrop2 |
| version | 0.4.0 |
| created_at | 2024-07-31 00:05:37.064992+00 |
| updated_at | 2025-03-04 21:31:47.359708+00 |
| description | Clone of smartcrop library in JavaScript |
| homepage | |
| repository | https://codeberg.org/ThetaDev/smartcrop.rs |
| max_upload_size | |
| id | 1320467 |
| size | 71,059 |
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.
It also includes a new feature: removing black borders around an image before finding the best crop.
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);