README
png-utils
Simple PNG utils
Installation
npm i png-utils
Example
Creates a 50x20 red 24-bits PNG and saves it in uni.png
const { raw24BitsToPng } = require('png-utils')
const fs = require('fs')
const width = 50
const height = 20
const data = Buffer.from(Array(width * height).fill(0).map((v,i) => {
return [ 0xff, 0x00, 0x00 ]
}).flat())
raw24BitsToPng(data, width, height)
.then(buffer => {
fs.writeFileSync('uni.png', buffer)
})
.catch(err => {
console.error(err.stack)
process.exit(1)
})
Usage
raw24BitsToPng : Buffer
Converts a raw 24-bits image into 24-bits PNG
Params
- rawBuffer (Buffer)
- width (Number)
- Height (Number)
Example
const buffer = Buffer.from([
0xff, 0x00, 0x00,
0xff, 0x00, 0x00,
0xff, 0x00, 0x00,
0xff, 0x00, 0x00,
0xff, 0x00, 0x00
])
const width = 5
const height = 1
const png = await raw24BitsToPng(buffer, width, height)
await fs.writeFile('output.png', png)