Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update toBuffer function, support RAW data #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions lib/ImagePrototypeInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down