Crop all transparent pixel around an image's edges.
You'll then need to bundle your code with a bundler.
npm install crop-browser
You don't need installation, just import from a CDN.
// With NPM
import crop from "crop-browser";
// Or simply use directly
import crop from "https://www.unpkg.com/crop-browser";
// Run the async function and display the result
(async () => {
const cropped = await crop("path/to/image.png");
// Display the file (for example)
document.body.appendChild(cropped);
})();
Name | Type | Default | Comment |
---|---|---|---|
input | String|any |
required | Path to the image to process or any type supported by Canvas.prototype.drawImage |
options | Options |
(see below) | Some options |
Name | Type | Default | Comment |
---|---|---|---|
outputFormat | String |
"png" |
Format of the output image ("png" or "jpeg" ) |
In addition, all options of detect-edges
are supported.
- Only want to detect content edges, see
detect-edges
- For the Node.js version see
crop-node
- For a CLI version see
crop-node-cli