Crates.io | apng |
lib.rs | apng |
version | 0.3.4 |
source | src |
created_at | 2019-10-10 02:53:37.251216 |
updated_at | 2024-02-14 14:46:06.038374 |
description | APNG Encoder. But it is tiny yet. |
homepage | |
repository | https://github.com/poccariswet/apng |
max_upload_size | |
id | 171345 |
size | 95,415 |
apng is animated png encoder for Rust, and made in pure Rust.
use apng::{Encoder, Frame, PNGImage};
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
fn main() {
let files = vec![
"rust_logo1.png",
"rust_logo2.png",
"rust_logo3.png",
"rust_logo4.png",
"rust_logo5.png",
"rust_logo6.png",
];
let mut png_images: Vec<PNGImage> = Vec::new();
for f in files.iter() {
png_images.push(apng::load_png(f).unwrap());
}
let path = Path::new(r"sample/out.png");
let mut out = BufWriter::new(File::create(path).unwrap());
let config = apng::create_config(&png_images, None).unwrap();
let mut encoder = Encoder::new(&mut out, config).unwrap();
let frame = Frame {
delay_num: Some(1),
delay_den: Some(2),
..Default::default()
};
match encoder.encode_all(png_images, Some(&frame)) {
Ok(_n) => println!("success"),
Err(err) => eprintln!("{}", err),
}
}
let mut i = 1;
for image in png_images.iter() {
i += 1;
let frame = Frame {
delay_num: Some(1),
delay_den: Some(i), // 2, 3, 4, 5, 6, 7
..Default::default()
};
encoder.write_frame(image, frame).unwrap();
}
Sample code is here.