0.2.1 • Published 8 years ago

binary-grid-image v0.2.1

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
8 years ago

binary-grid-image

Put in an image, get out an array of

[
  [ true, false, true],
  [ false, true, true],
  //...
]

where each boolean represents a hex in a tiled pattern.

true is positive space, false is negative space.

install

npm install binary-grid-image -g

use

From CLI:

binary-grid-image -i 'http://image.flaticon.com/icons/png/512/25/25231.png' -w 100 -h 100

This will print the array to stdout

From JS:

var grid = require('binary-grid-image')

// from a url
var url = 'http://image.flaticon.com/icons/png/512/25/25231.png'
grid(url, 100, 100, (err, arr) => {
  if (err) throw err
  else console.log(arr)
})

// or from a local path
grid('./my-cool-image.jpg', 100, 100, (err, arr) => {
  // do stuff ...
  var output = JSON.stringify(arr)
  require('fs').writeFileSync('out.json', output)
})

Optionally, you can set a threshold for the r, g, b, and alpha values.

// or, set one threshold value for r, g, b, and a
grid(url, 100, 100, (err, arr) => {
  if (err) throw err
  else console.log(arr)
}, 100) // values below (darker than) 100 will be true

api

grid(path/url, width, height, cb, [threshold=50])

Turn path or url to an image file supported by jimp into a 2D array of true false values, where width and height are the dimensions of the resulting array. Calls cb(array) when processing is done.

Optional threshold is a value between 0-255 - 50 by default. Values below (darker than) this threshold are true (positive space); lighter are false (negative space).

If you choose, you can set values for r,g,b,a individually, by passing in an array:

var grid = require('binary-grid-image')
var url = 'http://image.flaticon.com/icons/png/512/25/25231.png'
grid(url, 100, 100, (err, arr) => {
  if (err) throw err
  else console.log(arr)
}, [50, 50, 50, 50]) // here are the r, g, b, a threshold values

license

BSD

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago