Skip to content

Latest commit

 

History

History
49 lines (30 loc) · 980 Bytes

README.MD

File metadata and controls

49 lines (30 loc) · 980 Bytes

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.
or codesandbox.

Thanks Repo

trim-canvas

signature-pad