Converts a Buffer to PNG format -- very, very quickly.
It's pronounced: "lightn--PING!". As in, PING! Your PNG is ready before you can say lightning.
First, install it in your project: npm install --save node-lightnpng
Then use it.
'use strict'
// First, we'll build an ARGB Buffer with node-canvas:
// https://github.com/Automattic/node-canvas
//
// FOR NOW, alter the "canvas" dependency in your "package.json" to:
// "canvas": "adamhooper/node-canvas#toBuffer-raw"
// ... see https://github.com/Automattic/node-canvas/pull/819 for updates
const Canvas = require('canvas')
const canvas = new Canvas(640, 480)
const ctx = canvas.getContext('2d')
ctx.fillStyle = 'red'
ctx.fillRect(10, 10, 200, 340)
ctx.fillStyle = 'green'
ctx.fillRect(50, 50, 30, 400);
const cairoBuf = canvas.toBuffer('raw') // ARGB, native-endian data
// Now's where this library comes in: let's create a PNG!
const lightnpng = require('node-lightnpng')
var png = lightnpng.native_argb32_to_png(
cairoBuf,
640, // width (in px)
480, // height (in px)
canvas.stride // number of bytes per row of image
)
We start with zero features.
Features that don't inhibit speed are great.
For features that do slow things down, apply the rule: a 5 percent slowdown should make this library useful to three times as many people as already use it.
Basically, we allow no options at all ... except:
- Custom width, height and row stride
- Input conversion from ARGB32 to RGB24 by dropping the alpha channel
Some drawing libraries may align their arrays to machine word boundaries.
The stride
option specifies how many bytes are in each row.
BSD-style 2-clause license