fix: thumbnailification requires rgb8/rgba8 (#505)

This commit is contained in:
Paul Makles
2026-01-25 22:36:31 +00:00
committed by GitHub
parent 5d3e65e076
commit 413aa04dca
2 changed files with 22 additions and 0 deletions

View File

@@ -132,6 +132,17 @@ impl MediaRepository for MediaImpl {
let [w, h] = self.config.preview.get(tag).unwrap();
let image = image.thumbnail(image.width().min(*w as u32), image.height().min(*h as u32));
let image = match image {
DynamicImage::ImageRgb8(_) => image,
DynamicImage::ImageRgba8(_) => image,
_ => {
if image.has_alpha() {
image.to_rgba8().into()
} else {
image.to_rgb8().into()
}
}
};
let encoder = webp::Encoder::from_image(&image).expect("Could not create encoder.");
if self.config.webp_quality != 100.0 {
@@ -216,6 +227,17 @@ mod tests {
media.create_thumbnail(image, "emojis");
}
#[tokio::test]
async fn asset_test_floating_point_png() {
let media = MediaImpl::from_config().await;
let buf = include_bytes!("../../tests/assets/test-float.png");
assert_eq!(media.image_size_vec(buf, "image/png"), Some((300, 300)));
let mut reader = Cursor::new(buf);
let image = media.decode_image(&mut reader, "image/png").unwrap();
media.create_thumbnail(image, "avatars");
}
#[tokio::test]
async fn asset_test_corrupted_png() {
let media = MediaImpl::from_config().await;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB