crop-universal
v1.0.2
Published
Crop transparent pixel from image
Downloads
178
Maintainers
Readme
crop-universal
Crop all transparent pixel around an image's edges.
⚠️ This package is environment agnostic. It requires you to provide a Canvas
implementation. It'll be more simple for you to use:
- For browsers 👉
crop-browser
- For Node.js 👉
crop-node
- As a CLI 👉
crop-node-cli
Installation
npm install crop-universal
Usage
import crop from "crop-universal";
// You're in charge of providing a couple of function corresponding to your environment
const cropper = crop({ createCanvas, loadImage });
const url = "path/to/file.png";
const canvas = cropper(url);
Documentation
crop(environment)
| Name | Type | Default | Comment |
|-------------|----------|----------|------------------------------------------------------------------|
| environment | Object
| required | Object holding a createCanvas
and a loadImage
implementation |
This will return a Function
that you can use to crop.
crop(environment)(input, [options])
| Name | Type | Default | Comment |
|---------|-----------------------------------|-------------|-----------------------------------------------------------------------------------------------------|
| input | String\|Image\|HTMLImageElement
| required | Path to the image to process or any type supported by your Canvas.prototype.drawImage
environment |
| options | Options
| undefined
| Allow to forward options to detect-edges
|
This will return a canvas with the result drawn onto.