Socket
Book a DemoInstallSign in
Socket

canvasstream

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvasstream

Streamize canvas with puppeteer.

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

canvasstream

Streamize canvas with puppeteer.

Usage

You can create stream like below:

import canvasstream from 'canvasstream'
import fs from 'fs'

canvasstream({
  width: 1024,
  height: 768,
  source: `async (canvas) => {
    const ctx = canvas.getContext('2d')
    let r = 0

    const sleep = msec => new Promise(resolve => setTimeout(resolve, msec))

    for(let i=0; i<60*2; i++) {
      ctx.fillStyle = 'white'
      ctx.fillRect(0, 0, canvas.width, canvas.height)
      ctx.save()
      ctx.translate(canvas.width/2, canvas.height/2)
      ctx.rotate(r)
      ctx.beginPath()
      ctx.moveTo(0,0)
      ctx.lineTo(50, 50)
      ctx.lineWidth = 4
      ctx.strokeStyle = 'black'
      ctx.stroke()
      ctx.restore()
      r += 0.03

      await sleep(1000/60)
    }
  }`
}).pipe(fs.createWriteStream('./output.webm'))

Author

Yusuke Shibata

License

MIT

FAQs

Package last updated on 27 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts