Skip to content

Commit

Permalink
Merge pull request #207 from LGFae/support-for-apng
Browse files Browse the repository at this point in the history
support animated pngs
  • Loading branch information
LGFae authored Feb 13, 2024
2 parents 0105341 + d162c48 commit 6df8df0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/imgproc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fast_image_resize::{FilterType, PixelType, Resizer};
use image::{
codecs::{gif::GifDecoder, webp::WebPDecoder},
codecs::{gif::GifDecoder, png::PngDecoder, webp::WebPDecoder},
AnimationDecoder, DynamicImage, Frames, ImageFormat, RgbImage,
};
use std::{
Expand Down Expand Up @@ -66,6 +66,11 @@ impl ImgBuf {
.map_err(|e| format!("failed to decode Webp Image: {e}"))?
.has_animation()
}
Some(ImageFormat::Png) => {
PngDecoder::new(BufReader::new(File::open(path).unwrap()))
.map_err(|e| format!("failed to decode Png Image: {e}"))?
.is_apng()
}

_ => false,
}
Expand Down Expand Up @@ -118,6 +123,10 @@ impl ImgBuf {
Some(ImageFormat::WebP) => Ok(WebPDecoder::new(reader)
.map_err(|e| format!("failed to decode webp during animation: {e}"))?
.into_frames()),
Some(ImageFormat::Png) => Ok(PngDecoder::new(reader)
.map_err(|e| format!("failed to decode png during animation: {e}"))?
.apng()
.into_frames()),
_ => Err(format!("requested format has no decoder: {img_format:#?}")),
}
}
Expand Down

0 comments on commit 6df8df0

Please sign in to comment.