Restrict the size of raked images
This commit is contained in:
parent
6d6e3c52e3
commit
e401377db5
|
@ -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))?;
|
||||
|
|
Loading…
Reference in New Issue