autocrop-worker
v1.0.4
Published
A simple, fast autocrop library which automagically crops the image. The cropping related functions are based on autocrop.js. This library offloads image processing work from mainthread to workers using workerpool.
Downloads
32
Readme
autocrop-worker
A simple, fast autocrop library which automagically crops the image. The cropping related functions are based on autocrop.js https://github.com/lqez/autocrop.js. This library offloads image processing work from main thread to workers using workerpool.
Demo site: https://johnpremkumar.github.io/autocrop-worker/demo/
Install
$ npm install autocrop-worker
Usage
As ES6 Module with bundlers like webpack, etc.
import autocrop from 'autocrop-worker'
autocrop(<original_image_element>, (target_image_element), (options));
As legacy javascript files using script tags.
// workerpool need to be loaded before autocrop-worker.min.js
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/workerpool.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/autocrop-worker.min.js"></script>
...
<script>
autocrop(<original_image_element>, (target_image_element), (options));
</script>
If target_image_element
is set null
, it will replace original_image_element
with the cropped result.
Parameter
const autoCropDefaultOptions = {
bgColor: '#FFFFFF', // Background color.
alphaTolerance: 20, // Pixels that are transparent than this value are considered transparent.
colorTolerance: 20, // Pixels similar to the background color are considered as the background.
invertTolerance: 0.90, // Invert the image if most of non-transparent pixels are background color.
margin: '2%', // Margin
allowInvert: true, // Allow invert if needed.
marker: 'cropped', // Add a marker attribute to prevent duplicated cropping.
version: boolean|string /* Defaults to current timestamp. Used for avoiding crossorigin taint issues due to previous cache.
Set it to false for dataURL and blobs */
};
Example
Used By
License
MIT