redguard-preservation 0.6.2

A CLI tool to preserve Redguard files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use image::codecs::png::{CompressionType, FilterType, PngEncoder};
use image::{DynamicImage, ImageError};
use std::io::BufWriter;
use std::path::Path;

pub fn save_png(image: &DynamicImage, path: &Path, compress: bool) -> Result<(), ImageError> {
    let file = std::fs::File::create(path)?;
    let w = BufWriter::new(file);
    let (compression, filter) = if compress {
        (CompressionType::Default, FilterType::Adaptive)
    } else {
        (CompressionType::Fast, FilterType::NoFilter)
    };
    let encoder = PngEncoder::new_with_quality(w, compression, filter);
    image.write_with_encoder(encoder)
}