Skip to content

Commit

Permalink
support animated pngs
Browse files Browse the repository at this point in the history
  • Loading branch information
LGFae committed Feb 13, 2024
1 parent 0105341 commit d162c48
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 d162c48

Please sign in to comment.