Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

agilgur5/trim-canvas

Repository files navigation

trim-canvas

package-json releases commits
dt dy dm dw
build status code coverage
NPM

A tiny (< 100 LoC) library for trimming whitespace from a canvas element with no dependencies.

Installation

npm i -S trim-canvas

Usage

import trimCanvas from 'trim-canvas'
const canvas = document.createElement('canvas')
// do some drawing on it ...
trimCanvas(canvas)
// now the whitespace has been trimmed

If you don't want to mess with your existing canvas, then simply clone the canvas element beforehand.

trim-canvas returns the canvas element for easy chaining.

Example

Can see how trim-canvas is used inside of react-signature-canvas here. It includes a step for cloning the canvas.

Demo

You can see a demo of trim-canvas here.

(N.B. this is the demo for react-signature-canvas which depends on trim-canvas)

Credits

Credits go to @efc for writing a quick version of this in this issue and to the original StackOverflow Answer that was credited in that issue.

About

A tiny (< 100 LoC) library for trimming whitespace from a canvas element with no dependencies

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /