pixlzr

Crates.iopixlzr
lib.rspixlzr
version0.3.0
sourcesrc
created_at2022-10-07 14:09:27.401811
updated_at2024-02-01 12:30:11.611082
descriptionPixlzr - A rust lib and CLI for the pixlzr image format
homepagehttps://github.com/guiga-zalu/pixlzr-rust
repositoryhttps://github.com/guiga-zalu/pixlzr-rust
max_upload_size
id682873
size3,687,634
Guilherme Alves Ceobaniuk Zaluchi (guiga-zalu)

documentation

README

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.

Commit count: 11

cargo fmt