Coder Social home page Coder Social logo

text-pngify's Introduction

text-pngify

Convert text to pixels and save to png file.

'hello world' => hello world.png

hello world.png

I Have a Dream.txt => I Have a Dream.png

I Have a Dream.png

Install

npm i -s text-pngify

Usage

encode

const { encode } =  require('text-pngify');

// encode String => Uint8Array(PNG)

let u8a = encode('hello world');
// Uint8Array(80) [
//   137,  80, 78,  71,  13,  10,  26,  10,   0,  0,   0,  13,
//    73,  72, 68,  82,   0,   0,   0,   2,   0,  0,   0,   2,
//     8,   6,  0,   0,   0, 114, 182,  13,  36,  0,   0,   0,
//    23,  73, 68,  65,  84, 120,  94,  99, 200, 72, 205, 201,
//   201,  87, 40, 207, 103,  40, 202,  73,  97,  0,   1,   0,
//    50, 248,  4,  93, 192, 177, 254,  97,   0,  0,   0,   0,
//    73,  69, 78,  68, 174,  66,  96, 130
// ]

// toFile
require('fs').writeFileSync('o.png', u8a)

// toBase64
Buffer.from(u8a).toString('base64')
// iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAF0lEQVR4XmPISM3JyVcoz2coyklhAAEAMvgEXcCx/mEAAAAASUVORK5CYII=

decode

const { decode } =  require('text-pngify');

// decode Uint8Array(PNG) => String

//fromFile
let text = decode(require('fs').readFileSync('o.png'))
// "hello world"

//fromBase64
decode(Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAF0lEQVR4XmPISM3JyVcoz2coyklhAAEAMvgEXcCx/mEAAAAASUVORK5CYII=','base64'))
// "hello world"

text-pngify's People

Contributors

tangoboy avatar fengdi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.