trim-canvas-blank
v1.0.0
Published
A lightweight library for trim canvas blank.
Downloads
546
Maintainers
Readme
trim-canvas-blank
A lightweight library for trimming canvas blank, no dependencies.
Installation
npm
npm i -S trim-canvas-blank
yarn
yarn add trim-canvas-blank
Usage
import trimCanvas from "trim-canvas-blank";
const canvas = document.querySelector("canvas");
const image = document.querySelector(".render-img");
let outputCanvas;
// simple usage
outputCanvas = trimCanvas(canvas);
// or you can custom padding
outputCanvas = trimCanvas(canvas, {
padding: 12, // default 0
// padding: [24, 12, 24, 12], // [top, right, bottom, left]
});
// output
const src = outputCanvas.toDataURL("image/png");
image.src = src;
Demo
You can see a demo of trim-canvas-blank
here.