Function gifski::new

source ·
pub fn new(settings: Settings) -> GifResult<(Collector, Writer)>
Expand description

Start new encoding on two threads.

Encoding is always multi-threaded, and the Collector and Writer must be used on sepate threads.

You feed input frames to the Collector, and ask the Writer to start writing the GIF.

If you don’t start writing, then adding frames will block forever.

use gifski::*;

let (collector, writer) = gifski::new(Settings::default())?;
std::thread::scope(|t| -> Result<(), Error> {
    let frames_thread = t.spawn(move || {
        for i in 0..10 {
            collector.add_frame_png_file(i, format!("frame{i:04}.png").into(), i as f64 * 0.1)?;
        }
        drop(collector);
        Ok(())
    });

    writer.write(std::fs::File::create("demo.gif")?, &mut progress::NoProgress{})?;
    frames_thread.join().unwrap()
})?;
Ok::<_, Error>(())