diff --git a/README.md b/README.md index 9b536bf..0a14b32 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Example ```javascript var getPixels = require("get-pixels") -getPixels("lena.png", function(err, pixels) { +getPixels("lena.png", function(err, pixels, frameInfo) { if(err) { console.log("Bad image path") return @@ -28,17 +28,38 @@ Install npm install get-pixels -### `require("get-pixels")(url[, type], cb(err, pixels))` +### `require("get-pixels")(url[, type], cb(err, pixels, frameInfo))` Reads all the pixels from url into an ndarray. * `url` is the path to the file. It can be a relative path, an http url, a data url, or an [in-memory Buffer](http://nodejs.org/api/buffer.html). * `type` is an optional mime type for the image (required when using a Buffer) -* `cb(err, pixels)` is a callback which gets triggered once the image is loaded. +* `cb(err, pixels, framesInfo)` is a callback which gets triggered once the image is loaded. -**Returns** An ndarray of pixels in raster order having shape equal to `[width, height, channels]`. +**Returns** An ndarray of pixels in raster order having shape equal to `[width, height, channels]` and **frameInfo** param if available (for animated GIFs). **Note** For animated GIFs, a 4D array is returned with shape `[numFrames, width, height, 4]`, where each frame is a slice of the final array. +**frameInfo** is an Array of Objects with these fields: + +Name|Type|Description +----|-----|----------- +x | Integer | Image Left Position +y | Integer | Image Top Position +width | Integer | Image Width +height | Integer | Image Height +has_local_palette | Boolean | Image local palette presentation flag +palette_offset | Integer | Image palette offset +palette_size | Integer | Image palette size +data_offset | Integer | Image data offset +data_length | Integer | Image data length +transparent_index | Integer | Transparent Color Index +interlaced | Boolean | Interlace Flag +delay | Integer | Delay Time (1/100ths of a second) +disposal | Integer | Disposal method + +See GIF spec for details. Summary http://www.onicos.com/staff/iz/formats/gif.html + + Credits ======= (c) 2013-2014 Mikola Lysenko. MIT License diff --git a/dom-pixels.js b/dom-pixels.js index 7714528..5fd8cdd 100644 --- a/dom-pixels.js +++ b/dom-pixels.js @@ -35,6 +35,7 @@ function handleGif(data, cb) { return } if(reader.numFrames() > 0) { + var framesInfo = [] var nshape = [reader.numFrames(), reader.height, reader.width, 4] var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3]) var result = ndarray(ndata, nshape) @@ -42,13 +43,14 @@ function handleGif(data, cb) { for(var i=0; i 0) { + var framesInfo = [] var nshape = [reader.numFrames(), reader.height, reader.width, 4] try { var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3]) @@ -65,13 +66,14 @@ function handleGIF(data, cb) { for(var i=0; i