wonmor / intelli-image-crop

An NPM module, Intelli Image Crop, intelligently removes white spaces from raster images.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

intelli-image-crop

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

npm version


Screenshot-1

Usage

  1. Import the module...
const removeImageBlanks = require('intelli-image-crop'); // Legacy Javascript
import removeImageBlanks from 'intelli-image-crop'; // Modern Javascript (React)
  1. Usage example...
const imageObject = ...; // Your image object
const padding = 10; // Padding value
const cornerRadius = 20; // Corner radius value

const result = removeImageBlanks(imageObject, padding, cornerRadius);
  1. 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);

About

An NPM module, Intelli Image Crop, intelligently removes white spaces from raster images.

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%