Skip to content

feitian124/get-image-data

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Build status

Browser support

Install

$ npm install get-image-data

note: canvas is not installed alongside get-image-data

get-image-data requires automattic/node-canvas for its server/node variant, however, to avoid browser-only users from having to endure the native compilation process, it needs to be npm installed separately.

Usage

Browser & Server

var image = require('get-image-data')

image('./image.jpg', function(error, info) {
  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[i + 1]
    var blue = data[i + 2]
    var alpha = data[i + 3]
  }
})

Note

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.

License

MIT

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%