From 6f2ff53a17b91b6512b8e5d6e463b2b403d32c77 Mon Sep 17 00:00:00 2001 From: Arseniy Knyazev Date: Fri, 2 Feb 2024 01:05:15 +0500 Subject: [PATCH] Added image resizing As library says it is crucial to resize image to 128x128 before processing it --- src/util/color.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index 6498fab..8e8cecc 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -7,6 +7,7 @@ use crate::Schemes; use crate::util::image::fetch_image; use image::io::Reader as ImageReader; +use image::imageops::{resize, FilterType}; use super::arguments::{ColorFormat, Format, Source}; use super::image::source_color_from_image; @@ -164,15 +165,18 @@ pub fn get_source_color(source: &Source) -> Result<[u8; 4], Report> { .decode() .expect("failed to decode image") .into_rgba8(); - + let img = resize(&img, 128, 128, FilterType::Gaussian); + source_color_from_image(img)? } Source::WebImage { url } => { // test info!("Fetching image from {}", url); - let img = fetch_image(url)?; - source_color_from_image(img.into_rgba8())? + let img = fetch_image(url)?.into_rgba8(); + let img = resize(&img, 128, 128, FilterType::Gaussian); + + source_color_from_image(img)? } Source::Color(color) => { let src: Rgb = match color {