Converts a flat array of RGBA quadruplets (e.g. [ [1,2,3,0], [2,3,4,0], ... ] ) into a PNG base64 encoded datauri.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.babelrc
.eslintrc.json
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

rgba-to-datauri

Build Status Coverage Status

Converts either a flat array of RGBA quadruplets (array of 4 integers) or a flattened Buffer ([r,g,b,a,r,g,b,a,...]) into a PNG base64 encoded datauri.

TODO

  • More error handling and input validation.
  • Promisifying (right now convert is sync)

Installation

node.js

Install using npm:

$ npm install rgba-to-datauri

Examples

Node.JS

import {convert} from 'rgba-to-datauri';

const array = [
  [0,0,0,255], [0,0,0,255],
  [0,0,0,255], [0,0,0,255]
];

const buf = new Buffer([0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,255]);

// Should get a png base64 encoded datauri depicting a black 2px by 2px square
const uriFromArray = convert(array, 2, 2);
const uriFromBuffer = convert(buf, 2, 2);

Testing

To run the tests:

$ npm install
$ npm test

Contributing

If you wish to submit a pull request please update and/or create new tests for any changes you make and ensure the tests pass.

License

MIT - see LICENSE