get-image-data
Advanced tools
Comparing version
@@ -29,4 +29,8 @@ var shared = require('./shared') | ||
var data = shared(canvas) | ||
callback(null, data(image)) | ||
callback(null, { | ||
data: data(image), | ||
height: image.height, | ||
width: image.width | ||
}) | ||
} | ||
} |
@@ -20,4 +20,8 @@ var fs = require('fs') | ||
var data = shared(canvas) | ||
callback(null, data(image)) | ||
callback(null, { | ||
data: data(image), | ||
height: image.height, | ||
width: image.width | ||
}) | ||
}) | ||
} |
{ | ||
"name": "get-image-data", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "A browser/server utility that extracts RGBA data from images.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# get-image-data | ||
get-image-data is a browser/server utility that extracts RGBA data from images. | ||
get-image-data is a browser/server utility that extracts RGBA data from images. It also provides the image’s height and width. | ||
@@ -20,3 +20,7 @@ [](https://travis-ci.org/michaelrhodes/get-image-data) | ||
image('./image.jpg', function(error, 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) { | ||
@@ -32,3 +36,3 @@ var red = data[i] | ||
### Note | ||
The image data will contained within either a [Uint8ClampedArray](https://developer.mozilla.org/en-US/docs/Web/API/Uint8ClampedArray) or a [CanvasPixelArray](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPixelArray) depending on the environment. This shouldn’t be a problem, but it’s worth knowing. | ||
The image data will be contained within either a [Uint8ClampedArray](https://developer.mozilla.org/en-US/docs/Web/API/Uint8ClampedArray) or a [CanvasPixelArray](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPixelArray) depending on the environment. This shouldn’t be a problem, but it’s worth knowing. | ||
@@ -35,0 +39,0 @@ |
module.exports = { | ||
trad: 1960000, | ||
jerry: 2785280, | ||
astronaut: 2739200 | ||
trad: { height: 700, width: 700, length: 1960000 }, | ||
jerry: { height: 544, width: 1280, length: 2785280 }, | ||
astronaut: { height: 535, width: 1280, length: 2739200 } | ||
} |
@@ -6,22 +6,40 @@ var run = require('tape').test | ||
run('it works', function(test) { | ||
test.plan(3) | ||
image(path.trad, function(error, data) { | ||
test.plan(9) | ||
image(path.trad, function(error, info) { | ||
test.equal( | ||
data.length, expected.trad, | ||
'trad.jpg' | ||
info.data.length, expected.trad.length | ||
) | ||
test.equal( | ||
info.width, expected.trad.width | ||
) | ||
test.equal( | ||
info.height, expected.trad.height | ||
) | ||
}) | ||
image(path.jerry, function(error, data) { | ||
image(path.jerry, function(error, info) { | ||
test.equal( | ||
data.length, expected.jerry, | ||
'jerry.jpg' | ||
info.data.length, expected.jerry.length | ||
) | ||
test.equal( | ||
info.width, expected.jerry.width | ||
) | ||
test.equal( | ||
info.height, expected.jerry.height | ||
) | ||
}) | ||
image(path.astronaut, function(error, data) { | ||
image(path.astronaut, function(error, info) { | ||
test.equal( | ||
data.length, expected.astronaut, | ||
'astronaut.jpg' | ||
info.data.length, expected.astronaut.length | ||
) | ||
test.equal( | ||
info.width, expected.astronaut.width | ||
) | ||
test.equal( | ||
info.height, expected.astronaut.height | ||
) | ||
}) | ||
}) | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1105061
0.07%123
23%1
-50%40
11.11%