Skip to content

NewsNIng/trim-canvas-blank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A lightweight library for trimming canvas blank, no dependencies. https://newsning.github.io/trim-canvas-blank/

Resources

Stars

Watchers

Forks

Packages

No packages published