Restrict the size of raked images

This commit is contained in:
Olivier 'reivilibre' 2022-03-27 19:18:21 +01:00
parent 6d6e3c52e3
commit e401377db5
1 changed files with 9 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use chrono::{DateTime, FixedOffset, Utc};
use cylon::Cylon;
use futures_util::stream::StreamExt;
use html5ever::tendril::fmt::Slice;
use image::ImageFormat;
use image::{GenericImageView, ImageFormat};
use itertools::Itertools;
use lazy_static::lazy_static;
use log::debug;
@ -507,7 +507,14 @@ pub fn rake_icon(content: &[u8], content_type: &str) -> anyhow::Result<RakedIcon
let orig_size = content.len();
let mut cursor = Cursor::new(&content);
let image = image::load(&mut cursor, *format).context("Failed to load image")?;
let mut image = image::load(&mut cursor, *format).context("Failed to load image")?;
const WANTED_DIMENSIONS: u32 = 32;
let (w, h) = image.dimensions();
if w.max(h) > WANTED_DIMENSIONS {
image = image.thumbnail(WANTED_DIMENSIONS, WANTED_DIMENSIONS);
}
let webp_encoder =
webp::Encoder::from_image(&image).map_err(|err| anyhow!("webp fail: {}", err))?;