Intelli Image Crop intelligently removes white spaces from raster images. For Javascript and Typescript users.

- Import the module...
const removeImageBlanks = require('intelli-image-crop'); // Legacy Javascript
import removeImageBlanks from 'intelli-image-crop'; // Modern Javascript (React)
- Usage example...
const imageObject = ...; // Your image object
const padding = 10; // Padding value
const cornerRadius = 20; // Corner radius value
const result = removeImageBlanks(imageObject, padding, cornerRadius);
- Make sure the
imageObject
is rasterized (in pixels, not vectors) before you begin...
// Rasterize the canvas
const rasterizedCanvas = document.createElement("canvas");
// Make SURE you mutiply the width and height with the DPR (Device Pixel Ratio)
// for support on high-resolution displays!
rasterizedCanvas.width = viewerCanvas.offsetWidth * window.devicePixelRatio;
rasterizedCanvas.height = viewerCanvas.offsetHeight * window.devicePixelRatio;
const rasterizedContext = rasterizedCanvas.getContext("2d");
rasterizedContext.drawImage(viewerCanvas, 0, 0);