Skip to content

Create png images in pure javascript (modern & fast ES6 version using typed Arrays)

Notifications You must be signed in to change notification settings

IjzerenHein/pnglib-es6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pnglib-es6

Modern & fast version of the original javascript pnglib library.

This version uses typed-arrays and is roughly 3-4 x as fast as the original library.

Install

npm install pnglib-es6

Usage

import PNGImage from 'pnglib-es6';

// Create new PNG image, parameters (only indexed 8-bit pngs are supported at the moment):
// width (number)
// height (number)
// depth (number of palette entries)
// [backgroundColor] (optional background color, when omitted 'transparent' is used)
const image = new PNGImage(100, 100, 8);

// Add colors to the palette (uses tinycolor for converting the color)
const redColor = image.createColor('#FF0000');
const blueColor = image.createColor('blue');
const greenColor = image.createColor('rgba(0, 255, 0, 1)');

// Do some pixel drawing
image.setPixel(50, 50, redColor);
const color = image.getPixel(50, 50);
...

// Convert image to base-64
const base64 = image.getBase64();

// Or get the data-url which can be passed directly to an <img src>
const dataUri = image.getDataURL(); // data:image/png;base64,...

About

Create png images in pure javascript (modern & fast ES6 version using typed Arrays)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published