Awesome
electron-canvas-to-buffer
With Electron, turns a Canvas element into a Node Buffer.
This module uses Electron built-ins (native-image), so it is only useful within that environment.
Example
var canvasBuffer = require('electron-canvas-to-buffer')
var fs = require('fs')
// your canvas drawing
var canvas = document.createElement('canvas')
var context = canvas.getContext('2d')
context.fillRect(0, 0, 50, 50)
context.fillStyle = 'red'
context.fillRect(50, 10, 30, 20)
// as a buffer
var buffer = canvasBuffer(canvas, 'image/png')
// write canvas to file
fs.writeFile('image.png', buffer, function (err) {
throw err
})
You can run the above source through an Electron app with node-integration
enabled. It should also work with chromeo (still experimental):
chromeo index.js
Install
npm install electron-canvas-to-buffer --save
Usage
buf = canvasBuffer(canvas, [type], [quality])
Returns a Buffer representing the specified canvas
element. Parameters:
type
(String) either"image/png"
(default) or"image/jpeg"
quality
(Number) for JPG, decides the encoding quality (default 0.9)
License
MIT, see LICENSE.md for details.