Add a fit function to resize an image

Given a bounding box defined by the desired width and height, resize the
image to fit that box, maintaining the aspect ratio.

cargo test passes
This commit is contained in:
Nathan Fiedler
2015-06-10 21:27:58 -07:00
parent 56877aaad3
commit 5e091bf488
2 changed files with 39 additions and 0 deletions

View File

@ -97,3 +97,17 @@ fn test_write_to_blob() {
assert_eq!(512, wand.get_image_width());
assert_eq!(384, wand.get_image_height());
}
#[test]
fn test_fit() {
START.call_once(|| {
magick_wand_genesis();
});
let wand = MagickWand::new();
assert!(wand.read_image("tests/data/IMG_5745.JPG").is_ok());
assert_eq!(512, wand.get_image_width());
assert_eq!(384, wand.get_image_height());
wand.fit(240, 240);
assert_eq!(240, wand.get_image_width());
assert_eq!(180, wand.get_image_height());
}