Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support animated pngs #207

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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