#png #nodejs #conversion #tool #version #project

bin+lib pconvert-rust

Rust version of P(NG)Convert, a simple PNG conversion tool

14 releases

0.4.10 Feb 9, 2021
0.4.9 Jan 4, 2021
0.3.0 Jan 3, 2021
0.2.8 Jan 3, 2021
Download history 2/week @ 2021-03-07 28/week @ 2021-03-21 28/week @ 2021-03-28 28/week @ 2021-04-04 31/week @ 2021-04-11 19/week @ 2021-04-18 14/week @ 2021-04-25 15/week @ 2021-05-02 14/week @ 2021-05-16 14/week @ 2021-06-06 3/week @ 2021-06-20

72 downloads per month

Apache-2.0

6.5MB
3K SLoC

Rust 2.5K SLoC // 0.0% comments Python 189 SLoC // 0.1% comments JavaScript 87 SLoC Shell 19 SLoC // 0.2% comments

P(NG)Convert Rust

The Rust version of the famous P(NG)Convert from Hive Solutions.

This Rust crate can be used as a command line application, as a crate in another rust project, as a Web Assembly module (able to be used within JavaScript that targets web browsers or NodeJS) or as a Python package.

Command Line Application

Compiling & Executing

Build and run with:

cargo run

Alternatively, compile first with:

cargo build

and then run the binary with:

./target/debug/pconvert-rust

Additionally, for better code optimization, compile with the --release flag:

cargo build --release

and then run the release binary with:

./target/release/pconvert-rust

Usage

$ pconvert-rust
Usage: pconvert-rust <command> [args...]
where command can be one of the following: compose, convert, benchmark, version
$ pconvert-rust compose <dir>
$ pconvert-rust convert <file_in> <file_out>
$ pconvert-rust benchmark <dir> [--parallel]
$ pconvert-rust version

Example

// blends the provided image as a new image to be used
// under the current instance
let top = pconvert_rust::utils::read_png_from_file("top.png".to_string(), false).unwrap();
let mut bottom = pconvert_rust::utils::read_png_from_file("bottom.png".to_string(), false).unwrap();

// gathers the mask top blending algorithm function and
// uses it to blend both images
let blending_fn = pconvert_rust::blending::get_blending_algorithm(
    &pconvert_rust::blending::BlendAlgorithm::DestinationOver,
);
pconvert_rust::blending::blend_images(&mut bottom, &top, &blending_fn, &None);

// "outputs" the blended image contents to the `out.png` file
pconvert_rust::utils::write_png_to_file_d("out.png".to_string(), &bottom).unwrap();

WebAssembly (WASM) Module

Compiling & Executing

Follow this guide on how to install wasm-pack.

To build, use the wasm-extension feature:

wasm-pack build -- --features wasm-extension

To run the demo, follow this.

Usage

Check the demo site to see how to use the PConvert WASM module.

JavaScript API exposed:

// blends two File objects and returns a File object
blendImages(bot, top, target_file_name, algorithm, is_inline, options)

// blends two ImageData objects and returns an ImageData object
blendImagesData(bot, top, algorithm, is_inline, options)

// blends multiple File objects and returns a File object
blendMultiple(image_files, target_file_name, algorithm, algorithms, is_inline, options)

// blends multiple ImageData objects  and returns an ImageData object
blendMultipleData(images, algorithm, algorithms, is_inline, options)

// returns a JSON of module constants (e.g. ALGORITHMS, FILTER_TYPES, COMPILER_VERSION, ...)
getModuleConstants()

// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for `blendImages`
blendImagesBenchmarkAll(bot, top, is_inline)

// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for `blendMultiple`
blendMultipleBenchmarkAll(image_files, is_inline)

Python package

Compiling & Executing

This crate can be installed as a python package through the use of pip. Simply run:

pip install .

Usage

Check this folder for examples.

Import the python package with:

import pconvert_rust

Python API exposed. The parameter options is a python dictionary of optional parameters and if num_threads is specified with a value of 1 or more, the work load will be distributed across multiple threads (belonging to a internally managed thread pool).

# blends two images read from the local file system and writes the result to the file system
blend_images(bot_path, top_path, target_path, algorithm, is_inline, options)

# blends multiple images read from the local file system and writes the result to the file system
blend_multiple(img_paths, out_path, algorithm, algorithms, is_inline, options)

# returns a python dict with summary information about the internal thread pool (size, active jobs, queued jobs)
get_thread_pool_status()

# access module constants (e.g. ALGORITHMS, FILTER_TYPES, COMPILER_VERSION, ...)
pconvert_rust.ALGORITHMS
pconvert_rust.FILTER_TYPES
pconvert_rust.COMPILER_VERSION

Tests

For rust crate tests:

cargo test

For python API tests:

python setup.py test

For WASM API tests:

npm test

Documentation

Generate documentation using:

cargo doc --lib --all-features

License

P(NG)Convert Rust is currently licensed under the Apache License, Version 2.0.

Build Automation

Build Status Build Status GitHub crates Status PyPi Status npm Status License

Dependencies

~1.8–7MB
~105K SLoC