#image-compression #image #image-format #qoi #cli

bin+lib pixlzr

Pixlzr - A rust lib and CLI for the pixlzr image format

6 releases

0.3.0 Feb 1, 2024
0.2.2 Mar 16, 2023
0.2.1 Jan 11, 2023
0.1.1 Oct 7, 2022

#112 in Compression

Custom license

3MB
1.5K SLoC

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

Example

> pixlzr -i <image input> -o <image output> --force

Installing

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

Using via the API

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

use image::{open, DynamicImage};
use pixlzr::process::{
    process,
    tree::{
        process as tree_process,
        full as tree_full_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")?;

tree_full_process(&image, 0.25, Some(|v| v / 6.0)): DynamicImage
    .save("img-processed-tree-full.png")?;

Using the new API

// Importing
use image::DynamicImage;
use pixlzr::{FilterType, Pixlzr};
// Convert to
let png: DynamicImage = ::image::open("img.png");

let mut pix = Pixlzr::from_image(&img, 64, 64u32);
pix.shrink_by(FilterType::Gaussian, 0.8);

pix.save("pix-lized image.pixlzr")?;
// Convert from
let pix = Pixlzr::open("pix-lized image.pixlzr")?;
let img = pix.to_image(FilterType::Nearest)?;
img.save("reduced-img.png");

CLI

Fot CLI usage, install with

> cargo install pixlzr

The CLI can be understood with a run of pixlzr -h.

Pixlzr - A rust lib and CLI for the pixlzr image format

Usage: pixlzr [OPTIONS] --input <INPUT> --output <OUTPUT>

Options:
  -i, --input <INPUT>
          The input image file
  -o, --output <OUTPUT>
          The output image file
  -b, --block-width <BLOCK_WIDTH>
          The width of each block
          [default: 64]
      --block-height <BLOCK_HEIGHT>
          The height of each block
  -k, --shrinking-factor <SHRINKING_FACTOR>
          The shrinking factor: [+|-][1/][D][.D]
          If negative, is passed through max(0, 1 - x)
          [default: 1]
  -f, --filter <FILTER>
          The filter used when resizing the image blocks
          [default: lanczos3]
          [possible values: nearest, triangle, catmull-rom, gaussian, lanczos3]
  -d, --direction-wise <DIRECTION_WISE>
          Direction-wise scan
          [possible values: true, false]
      --force
          If image-2-image, force shrinking?
  -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.

Dependencies

~3–7MB
~94K SLoC