get-image-data

A browser/server utility that extracts RGBA data from images.

get-image-data

get-image-data is a browser/server utility that extracts RGBA data from images. It also provides the image’s height and width.

$ npm install get-image-data
var image = require('get-image-data')
 
image('./image.jpg', function(errorinfo) {
  var height = info.height
  var width = info.width
  var data = info.data
 
  for (var i = 0, l = data.length, i < l; i += 4) {
    var red = data[i]
    var green = data[+ 1]
    var blue = data[+ 2]
    var alpha = data[+ 3]  
  }
})

The image data will be contained within either a Uint8ClampedArray or a CanvasPixelArray depending on the environment. This shouldn’t be a problem, but it’s worth knowing.

MIT