A lossy image compression algorithm, based in a per-block level of detail detection, implemented in Rust.
Just put pixlzr = "0"
as one of the [dependencies]
into your Cargo.toml
.
Now, the crate pixlzr
have two parallel APIs, with different uses and functionalities.
The base use, of reducing / shrinking a crate image::DynamicImage
, is present in both. But in the future, the old API will be either deleted or rewritten based on the new one, which supports file saving / readding.
```rust use image::{open, DynamicImage}; use pixlzr::process::{ process, tree::{ process as treeprocess, full as treefull_process } };
// ...
let image: DynamicImage = open("img.png")?;
process(&image, 64, Some(|v| v / 4.0)): DynamicImage .save("img-processed.png")?;
tree_process(&image, 64, 0.25, Some(|v| v / 6.0)): DynamicImage .save("img-processed-tree.png")?;
treefullprocess(&image, 0.25, Some(|v| v / 6.0)): DynamicImage .save("img-processed-tree-full.png")?; ```
rust
// Importing
use image::{open, DynamicImage};
use pixlzr::{FilterType, Pixlzr};
```rust // Convert to let png: DynamicImage = open("img.png");
let mut pix = Pixlzr::fromimage(&img, 64, 64u32); pix.shrinkby(FilterType::Gaussian, 0.8);
pix.save("pix-lized image.pixlzr")?; ```
rust
// Convert from
let pix = Pixlzr::open("pix-lized image.pixlzr")?;
let img = pix.to_image(FilterType::Nearest)?;
img.save("reduced-img.png");
The CLI can be understood with a run of pixlzr -h
.
```txt Pixlzr - A rust lib and CLI for the pixlzr image format
Usage: pixlzr [OPTIONS] --input --output
Options: -i, --input The input image file -o, --output
It converts from and to the pixlzr
format, with use of the crate image
.
Yet to be written...
Please check GitHub:guiga-zalu/smart-pixelizer, as it's the implementation in Node JS.