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:
Alternatively, compile first with:
and then run the binary with:
Additionally, for better code optimization, compile with the --release
flag:
and then run the release binary with:
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 = read_png_from_file.unwrap;
let mut bottom = read_png_from_file.unwrap;
// gathers the mask top blending algorithm function and
// uses it to blend both images
let blending_fn = get_blending_algorithm;
blend_images;
// "outputs" the blended image contents to the `out.png` file
write_png_to_file_d.unwrap;
WebAssembly (WASM) Module
Compiling & Executing
Follow this guide on how to install wasm-pack
.
To build, use the wasm-extension
feature:
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
// blends two ImageData objects and returns an ImageData object
// blends multiple File objects and returns a File object
// blends multiple ImageData objects and returns an ImageData object
// returns a JSON of module constants (e.g. ALGORITHMS, FILTER_TYPES, COMPILER_VERSION, ...)
// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for `blendImages`
// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for `blendMultiple`
Python package
Compiling & Executing
This crate can be installed as a python package through the use of pip
. Simply run:
Usage
Check this folder for examples.
Import the python package with:
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
# blends multiple images read from the local file system and writes the result to the file system
# returns a python dict with summary information about the internal thread pool (size, active jobs, queued jobs)
# access module constants (e.g. ALGORITHMS, FILTER_TYPES, COMPILER_VERSION, ...)
Tests
For rust crate tests:
For python API tests:
For WASM API tests:
Documentation
Generate documentation using:
License
P(NG)Convert Rust is currently licensed under the Apache License, Version 2.0.