From 5b8b287924e383e12b5378d32d4f0be5836c9aa9 Mon Sep 17 00:00:00 2001 From: Anatoly Y Date: Thu, 11 Oct 2018 14:03:27 +0700 Subject: [PATCH 1/3] Pass framesInfo to the CallBack --- dom-pixels.js | 6 ++++-- node-pixels.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dom-pixels.js b/dom-pixels.js index 7714528..8ed5e68 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 Date: Fri, 12 Oct 2018 11:43:40 +0700 Subject: [PATCH 2/3] Styling. Additional docs --- README.md | 29 ++++++++++++++++++++++++----- dom-pixels.js | 6 +++--- node-pixels.js | 4 ++-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9b536bf..acd4813 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,14 +28,33 @@ 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. - -**Returns** An ndarray of pixels in raster order having shape equal to `[width, height, channels]`. +* `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]` and **frameInfo** param if available (for animated GIFs). +**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 **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. diff --git a/dom-pixels.js b/dom-pixels.js index 8ed5e68..5fd8cdd 100644 --- a/dom-pixels.js +++ b/dom-pixels.js @@ -35,7 +35,7 @@ function handleGif(data, cb) { return } if(reader.numFrames() > 0) { - var framesInfo = []; + 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) @@ -50,7 +50,7 @@ function handleGif(data, cb) { cb(err) return } - cb(null, result.transpose(0,2,1), framesInfo); + cb(null, result.transpose(0,2,1), framesInfo) } else { var nshape = [reader.height, reader.width, 4] var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2]) @@ -134,4 +134,4 @@ module.exports = function getPixels(url, type, cb) { defaultImage(url, cb) } } -} \ No newline at end of file +} diff --git a/node-pixels.js b/node-pixels.js index d05024b..7a6d911 100644 --- a/node-pixels.js +++ b/node-pixels.js @@ -53,7 +53,7 @@ function handleGIF(data, cb) { return } if(reader.numFrames() > 0) { - var framesInfo = []; + var framesInfo = [] var nshape = [reader.numFrames(), reader.height, reader.width, 4] try { var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3]) @@ -73,7 +73,7 @@ function handleGIF(data, cb) { cb(err) return } - cb(null, result.transpose(0,2,1), framesInfo); + cb(null, result.transpose(0,2,1), framesInfo) } else { var nshape = [reader.height, reader.width, 4] var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2]) From e9795ad2d5051f4a815b798a108920ea56fe53f5 Mon Sep 17 00:00:00 2001 From: Anatoly Y Date: Fri, 12 Oct 2018 21:03:45 +0700 Subject: [PATCH 3/3] the README correction --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index acd4813..0a14b32 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ Reads all the pixels from url into an ndarray. * `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]` 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 @@ -56,7 +59,6 @@ disposal | Integer | Disposal method See GIF spec for details. Summary http://www.onicos.com/staff/iz/formats/gif.html -**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. Credits =======