Skip to content

Commit

Permalink
fix: convert images to RGB8 (without alpha) before encoding into JPEG
Browse files Browse the repository at this point in the history
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: <image-rs/image#2211>
  • Loading branch information
link2xt committed Apr 23, 2024
1 parent 43fc55e commit aff6bf9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// (<https://github.com/image-rs/image/issues/2211>).
img.clone().into_rgb8().write_with_encoder(encoder)?;
}
}
Ok(())
Expand Down

0 comments on commit aff6bf9

Please sign in to comment.