From 6f22132b8da3c6de8fcd3cfb6f61872a21476756 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 7 Jul 2021 11:15:37 +0200 Subject: [PATCH] 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 --- components/imageproc/src/lib.rs | 7 +++++-- components/imageproc/tests/resize_image.rs | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/components/imageproc/src/lib.rs b/components/imageproc/src/lib.rs index 4d6328a4..fedd98ac 100644 --- a/components/imageproc/src/lib.rs +++ b/components/imageproc/src/lib.rs @@ -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 diff --git a/components/imageproc/tests/resize_image.rs b/components/imageproc/tests/resize_image.rs index 0e0e8f37..7fbfe21f 100644 --- a/components/imageproc/tests/resize_image.rs +++ b/components/imageproc/tests/resize_image.rs @@ -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);