imgproc: Don't upscale images in the Fit op, fix a bug in comment in #1542 (#1545)

* imgproc: Don't upscale images in the Fit op, fix  #1542

* imgproc: Remove FIXMEs that have been addressed
This commit is contained in:
Vojtech Kral 2021-07-07 11:15:37 +02:00 committed by GitHub
parent 96e28ddd5c
commit 6f22132b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -139,6 +139,10 @@ impl ResizeOp {
res.resize((w as u32, h))
}
Fit(w, h) => {
if orig_w <= w && orig_h <= h {
return res; // ie. no-op
}
let orig_w_h = orig_w as u64 * h as u64;
let orig_h_w = orig_h as u64 * w as u64;
@ -220,7 +224,7 @@ impl Format {
}
"jpeg" | "jpg" => Ok(Jpeg(jpg_quality)),
"png" => Ok(Png),
"webp" => Ok(WebP(quality)), // FIXME: this is undoc'd
"webp" => Ok(WebP(quality)),
_ => Err(format!("Invalid image format: {}", format).into()),
}
}
@ -342,7 +346,6 @@ impl ImageOp {
}
}
// FIXME: Explain this in the doc
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct EnqueueResponse {
/// The final URL for that asset

View File

@ -95,6 +95,11 @@ fn resize_image_fit2() {
image_op_test("jpg.jpg", "fit", Some(160), Some(180), "auto", "jpg", 142, 180, 300, 380);
}
#[test]
fn resize_image_fit3() {
image_op_test("jpg.jpg", "fit", Some(400), Some(400), "auto", "jpg", 300, 380, 300, 380);
}
#[test]
fn resize_image_fill1() {
image_op_test("jpg.jpg", "fill", Some(100), Some(200), "auto", "jpg", 100, 200, 300, 380);