copy-canvas

1.0.0 • Public • Published

copy-canvas

a more symantic way to duplicate an html5 canvas

Build Status npm version

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install copy-canvas --save

Usage

// require module
var copyCanvas = require('copy-canvas');
 
// create canvas
let canvas = document.createElement('canvas')
 
// draw a circle
let ctx = canvas.getContext('2d')
ctx.beginPath()
ctx.arc(150, 100, 50, 0, 2 * Math.PI)
ctx.stroke()
 
// copy canvas
let copy = copyCanvas(canvas)
 
// verify
let copyData = copy.toDataURL('image/png')
let canvasData = canvas.toDataURL('image/png')
copyData === canvasData // true
copy.width === canvas.width // true
copy.height === canvas.height // true

API

copyCanvas(canvas) provided a canvas, returns a new canvas copy

License

MIT

Package Sidebar

Install

npm i copy-canvas

Weekly Downloads

29

Version

1.0.0

License

MIT

Last publish

Collaborators

  • willhoag