2 releases
new 0.1.1 | Nov 20, 2024 |
---|---|
0.1.0 | Jun 18, 2024 |
#37 in #image-encoding
25 downloads per month
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
~225KB