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

png_codec

A minimal pure Rust PNG encoder

2 releases

0.1.1 Nov 20, 2024
0.1.0 Jun 18, 2024

#815 in Images

Download history 22/week @ 2024-09-16 23/week @ 2024-09-23 7/week @ 2024-09-30 6/week @ 2024-10-07 7/week @ 2024-10-21 15/week @ 2024-10-28 3/week @ 2024-11-04 132/week @ 2024-11-18 10/week @ 2024-11-25 19/week @ 2024-12-02 26/week @ 2024-12-09

187 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

~235KB