From 313ab4ed044a446acebc5c627ed5d8b320ed98c6 Mon Sep 17 00:00:00 2001 From: michuNEEO Date: Tue, 18 Aug 2015 20:39:55 +0200 Subject: [PATCH] update toBuffer function, support RAW data --- README.md | 11 +++++++++++ lib/ImagePrototypeInit.js | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 890a9429..bd8c327b 100644 --- a/README.md +++ b/README.md @@ -641,6 +641,7 @@ encoded data as a NodeJS Buffer object. - `"jpg"` - `"png"` - `"gif"` + - `"raw"` 0. `params {Object}`: **Optional** Format-specific parameters (See below). 0. `callback {Function(err, buffer)}` @@ -685,6 +686,16 @@ The `params` object should have the following fields: channel of the pixel is above this threshold, this pixel will be considered as opaque; otherwise it will be transparent. +##### RAW + +No `params` object is supported. The raw image returns an object which contains +the following fields: + + - `buffer {Buffer}`: Pixeldata + - `width {Integer}`: Image width + - `height {Integer}`: Image height + + #### Write to file Write encoded binary image data directly to a file. diff --git a/lib/ImagePrototypeInit.js b/lib/ImagePrototypeInit.js index d5c96d4c..d439fd8d 100644 --- a/lib/ImagePrototypeInit.js +++ b/lib/ImagePrototypeInit.js @@ -587,6 +587,13 @@ params.threshold, encoderCb ); + } else if (type === 'raw') { + var rawImg = { + buffer: that.__lwip.buffer(), + width: that.__lwip.width(), + height: that.__lwip.height() + }; + encoderCb(null, rawImg); } else throw Error('Unknown type \'' + type + '\''); function encoderCb(err, buffer) {