From 8e2a37c3eb969e0ee9b856470ecc15a4a168d7d5 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 20 Nov 2021 18:05:48 +0100 Subject: [PATCH] Change output bit depth to fixed size rgb8 (with alpha for png) Signed-off-by: trivernis --- Cargo.toml | 2 +- src/lib.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05cd0fc..a46d0ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ readme = "README.md" license = "Apache-2.0" authors = ["trivernis "] description = "An image thumbnail creation library" -version = "0.1.0" +version = "0.2.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index ab7ef9d..019fc78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,15 +42,16 @@ pub struct Thumbnail { impl Thumbnail { /// Writes the bytes of the image in a png format pub fn write_png(self, writer: &mut W) -> ThumbResult<()> { - self.inner.write_to(writer, ImageOutputFormat::Png)?; + let image = DynamicImage::ImageRgba8(self.inner.into_rgba8()); + image.write_to(writer, ImageOutputFormat::Png)?; Ok(()) } /// Writes the bytes of the image in a jpeg format pub fn write_jpeg(self, writer: &mut W, compression: u8) -> ThumbResult<()> { - self.inner - .write_to(writer, ImageOutputFormat::Jpeg(compression))?; + let image = DynamicImage::ImageRgb8(self.inner.into_rgb8()); + image.write_to(writer, ImageOutputFormat::Jpeg(compression))?; Ok(()) }