1.0.0 • Published 5 years ago

png-utils v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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)
1.0.0

5 years ago