Giter Club home page Giter Club logo

apng's Introduction

apng

apng at crates.io apng at docs.rs License apng at GitHub Actions

apng is animated png encoder for Rust, and made in pure Rust.

Example usage

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),
    }
}

Customize each frame speed

    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.

License

MIT

See also

Reference

apng's People

Contributors

chandlerswift avatar marius8510000-bot avatar mokurin000 avatar orhun avatar palladinium avatar phoekz avatar poccariswet avatar szabgab avatar vankessel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apng's Issues

modify examples file

like

[[example]]
name = "sample1"
path = "examples/***.rs"

[[example]]
name = "sample2"
path = "examples/***.rs"
...

color bug

rust_logo2とrust_logo3γŒεŒγ˜θ‰²γ«γͺってしまっている

require APNG structure?

ζœ¬ε½“γ«εΏ…θ¦γ‹γ©γ†γ‹θ€ƒγˆγ‚‹γ€
create_configを、εˆ₯γ«γ‚‚γŸγ›γ°γ‚ˆγ•γγ†

`errors` module is private

Hi!

I'm trying to wrap APNGError in my application like this:

/* Custom error implementation */
#[derive(Debug, ThisError)]
pub enum AppError {
    // ...
    #[error("APNG error: `{0}`")]
    Apng(#[from] apng::errors::APNGError),
    // ...
}

But I get the following errors:

error[E0603]: module `errors` is private
  --> src/app.rs:51:21
   |
51 |     Apng(#[from] apng::errors::APNGError),
   |                        ^^^^^^ private module
   |
note: the module `errors` is defined here
  --> /home/orhun/.cargo/registry/src/github.com-1ecc6299db9ec823/apng-0.2.0/src/lib.rs:2:1
   |
2  | mod errors;
   | ^^^^^^^^^^^

error[E0599]: the method `as_dyn_error` exists for reference `&apng::errors::APNGError`, but its trait bounds were not satisfied
  --> src/app.rs:50:10
   |
50 |     #[error("APNG error: `{0}`")]
   |             ^^^^^^^^^^^^^^^^^^^ method cannot be called on `&apng::errors::APNGError` due to unsatisfied trait bounds
   | 
  ::: /home/orhun/.cargo/registry/src/github.com-1ecc6299db9ec823/apng-0.2.0/src/errors.rs:7:1
   |
7  | pub enum APNGError {
   | ------------------
   | |
   | doesn't satisfy `apng::errors::APNGError: AsDynError`
   | doesn't satisfy `apng::errors::APNGError: std::error::Error`
   |
   = note: the following trait bounds were not satisfied:
           `apng::errors::APNGError: std::error::Error`
           which is required by `apng::errors::APNGError: AsDynError`
           `&apng::errors::APNGError: std::error::Error`
           which is required by `&apng::errors::APNGError: AsDynError`

error: aborting due to 2 previous errors

First error is due to errors module being private. Applying the following diff solves the issue:

diff --git a/src/lib.rs b/src/lib.rs
index e0cb98b..ef3a84f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
 mod apng;
-mod errors;
+pub mod errors;
 mod png;
 
 pub use crate::apng::*;

Second error is caused by the failure crate. It's fixed in #21

My question is: can we make errors module public? Or at least make APNGError public? I think it's important to expose these error types for use cases like mine.

What do you think? I'd like to provide a PR about this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.