#png #image-encoding #image #encoder #encoding

png_codec

A minimal pure Rust PNG encoder

1 unstable release

0.1.0 Jun 18, 2024

#41 in #image-encoding

Download history 8/week @ 2024-06-23 17/week @ 2024-08-04 21/week @ 2024-09-15 24/week @ 2024-09-22 7/week @ 2024-09-29 6/week @ 2024-10-06

58 downloads per month

Apache-2.0 OR Zlib

30KB
791 lines

A pure Rust PNG encoder


lib.rs:

A library for encoding PNG images, supporting indexed images.

Getting Started

Add the following to your Cargo.toml.

[dependencies.png_codec]
version = "0.1"

Example

let mut data = vec![0u8; 512 * 512];
for i in 0..512 * 512 {
    data[i] = (i % 7) as u8;
}
let png = png_codec::IndexedImage {
    height: 512,
    width: 512,
    pixels: &data,
    palette: &[
        Rgba::new(0, 0, 0, 255),
        Rgba::new(255, 0, 255, 255),
        Rgba::new(255, 0, 0, 255),
        Rgba::new(0, 10, 90, 255),
        Rgba::new(255, 0, 0, 200),
        Rgba::new(255, 1, 90, 255),
        Rgba::new(0, 10, 90, 255),
    ],
};
let encoded = png.encode_png(5).unwrap();
std::fs::write("graphic.png", &encoded).expect("Failed to save image");

Dependencies

~295KB