0.0.2 • Published 6 years ago

data-to-png v0.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

data-to-png

NPM version NPM
downloads

A Javascript utility that lets you encode any data to png.

Install

yarn add data-to-png

Usage

import { encode } from 'data-to-png';

encode('Hello World!').then((png) => {
  // Do something awesome with your png!
});

Example

Send jquery as a png from an express app to the browser.

const fs = require('fs');
const express = require('express');
const { encode } = require('data-to-png');

const app = express();

app.get('/test', function (req, res) {
  fs.readFile('./jquery-3.1.1.min.js', 'utf8', (error, data) => {
    encode(data).then((png) => {
      res.writeHead(200, {
        'Content-Type': 'image/png',
        'Content-Length': png.length,
      });
      res.end(png);
    })
  });
});

app.listen(8080, function () {
  console.log('Server listening on port 8080!');
});

The server will respond with the following png:

jquery-3.1.1.min.js.png

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

License

MIT