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.
Build and run with:
bash
cargo run
Alternatively, compile first with:
bash
cargo build
and then run the binary with:
bash
./target/debug/pconvert-rust
Additionally, for better code optimization, compile with the --release
flag:
bash
cargo build --release
and then run the release binary with:
bash
./target/release/pconvert-rust
console
$ pconvert-rust
Usage: pconvert-rust <command> [args...]
where command can be one of the following: compose, convert, benchmark, version
console
$ pconvert-rust compose <dir>
console
$ pconvert-rust convert <file_in> <file_out>
console
$ pconvert-rust benchmark <dir> [--parallel]
console
$ pconvert-rust version
```rust // blends the provided image as a new image to be used // under the current instance let top = pconvertrust::utils::readpngfromfile("top.png".tostring(), false).unwrap(); let mut bottom = pconvertrust::utils::readpngfromfile("bottom.png".tostring(), false).unwrap();
// gathers the mask top blending algorithm function and // uses it to blend both images let blendingfn = pconvertrust::blending::getblendingalgorithm( &pconvertrust::blending::BlendAlgorithm::DestinationOver, ); pconvertrust::blending::blendimages(&mut bottom, &top, &blendingfn, &None);
// "outputs" the blended image contents to the out.png
file
pconvertrust::utils::writepngtofiled("out.png".tostring(), &bottom).unwrap();
```
Follow this guide on how to install wasm-pack
.
To build, use the wasm-extension
feature:
bash
wasm-pack build -- --features wasm-extension
To run the demo, follow this.
Check the demo site to see how to use the PConvert WASM module.
JavaScript API exposed:
```javascript // blends two File objects and returns a File object blendImages(bot, top, targetFileName, algorithm, isInline, options)
// blends two ImageData objects and returns an ImageData object blendImagesData(bot, top, algorithm, isInline, options)
// blends multiple File objects and returns a File object blendMultiple(imageFiles, targetFileName, algorithm, algorithms, isInline, options)
// blends multiple ImageData objects and returns an ImageData object blendMultipleData(images, algorithm, algorithms, isInline, options)
// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for blendImages
blendImagesBenchmarkAll(bot, top, isInline)
// benchmarks and prints to console various times for different combinations of blending algorithms, compression algorithms and filters for blendMultiple
blendMultipleBenchmarkAll(imageFiles, isInline)
// returns a JSON of module constants (e.g. ALGORITHMS, FILTERTYPES, COMPILERVERSION, ...) getModuleConstants() ```
This crate can be installed as a python package through the use of pip
. Simply run:
bash
pip install .
Check this folder for examples.
Import the python package with:
python
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).
```python
blendimages(botpath, toppath, targetpath, algorithm, is_inline, options)
blendmultiple(imgpaths, outpath, algorithm, algorithms, isinline, options)
getthreadpool_status()
pconvertrust.ALGORITHMS pconvertrust.FILTERTYPES pconvertrust.COMPILER_VERSION ```
For rust crate tests:
bash
cargo test
For python API tests:
bash
python setup.py test
For WASM API tests:
bash
npm test
Generate documentation using:
bash
cargo doc --lib --all-features
P(NG)Convert Rust is currently licensed under the Apache License, Version 2.0.