#gif #image

bin+lib gift

A library for reading and writing GIF images

13 releases (breaking)

0.10.0 Oct 24, 2020
0.9.1 Jun 25, 2020
0.8.0 May 20, 2020
0.5.0 Mar 28, 2020
0.3.1 May 29, 2019

#565 in Encoding

Download history 55/week @ 2022-08-12 35/week @ 2022-08-19 113/week @ 2022-08-26 19/week @ 2022-09-02 57/week @ 2022-09-09 12/week @ 2022-09-16 13/week @ 2022-09-23 63/week @ 2022-09-30 18/week @ 2022-10-07 7/week @ 2022-10-14 10/week @ 2022-10-21 75/week @ 2022-10-28 24/week @ 2022-11-04 38/week @ 2022-11-11 44/week @ 2022-11-18 86/week @ 2022-11-25

196 downloads per month
Used in ntcip

MIT/Apache

115KB
3K SLoC

GIFt

A Rust library for encoding and decoding GIF images.

Documentation

https://docs.rs/gift

Decoding

use gift::Decoder;
use std::fs::File;
use std::io::BufReader;

let gif = BufReader::new(File::open("example.gif")?);
for step in Decoder::new(gif) {
    // was there a decoding error?
    let raster = step?.raster();
    // ... work with raster
}

Encoding

use gift::{Encoder, Step};
use pix::{gray::Gray8, Palette, Raster, rgb::SRgb8};
use std::error::Error;
use std::io::Write;

fn encode<W: Write>(mut w: W) -> Result<(), Box<dyn Error>> {
    let mut raster = Raster::<Gray8>::with_clear(4, 4);
    // ... initialize raster ...
    let mut palette = Palette::new(2);
    // ... initialize palette ...
    let step = Step::with_indexed(raster, palette);
    let mut enc = Encoder::new(&mut w).into_step_enc();
    enc.encode_step(&step)?;
    Ok(())
}

NOTE: building a palette from 24- or 32-bit rasters is not yet implemented.

Utility

The library comes with a gift command-line utility, which can show the blocks within GIF files.

cargo install gift --features=cmd

NOTE: This utility is a work-in-progress, and some features are not implemented.

Dependencies

~0.2–0.8MB
~16K SLoC