A lossy image compression algorithm, based in a per-block level of detail detection, implemented in Rust.

pixzlr

Crate downloads Crate recent downloads Crate version Last GitHub commit

Installing

Just put pixlzr = "0" as one of the [dependencies] into your Cargo.toml.

Using

Before using it

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.

Using the old API

```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")?; ```

Using the new API

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");

CLI

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 The output image file -b, --block-width The width of each block [default: 64] --block-height The height of each block -k, --shrink-by The shrinking factor [default: 1] --filter The filter used when resizing the image blocks [default: lanczos3] [possible values: nearest, triangle, catmull-rom, gaussian, lanczos3] -h, --help Print help (see more with '--help') -V, --version Print version ```

It converts from and to the pixlzr format, with use of the crate image.

Core concept

Yet to be written...
Please check GitHub:guiga-zalu/smart-pixelizer, as it's the implementation in Node JS.