From aff6bf94028b980aac96b5cc83a2d96c124792b0 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 22 Apr 2024 18:40:37 +0000 Subject: [PATCH] fix: convert images to RGB8 (without alpha) before encoding into JPEG Otherwise an error "The encoder or decoder for Jpeg does not support the color type `Rgba8`" is returned if image has an alpha channel. This is caused by the recent change of JPEG encoder in `image` crate: --- src/blob.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blob.rs b/src/blob.rs index a784062dcb..b850be2f4a 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -698,7 +698,10 @@ fn encode_img( ImageOutputFormat::Png => img.write_to(&mut buf, ImageFormat::Png)?, ImageOutputFormat::Jpeg { quality } => { let encoder = JpegEncoder::new_with_quality(&mut buf, quality); - img.write_with_encoder(encoder)?; + // Convert image into RGB8 to avoid the error + // "The encoder or decoder for Jpeg does not support the color type Rgba8" + // (). + img.clone().into_rgb8().write_with_encoder(encoder)?; } } Ok(())