mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Allow Stream-based input of raw pixel data #1579
This commit is contained in:
parent
9ee377963e
commit
83cdb558f6
@ -15,6 +15,9 @@ Requires libvips v8.7.4.
|
|||||||
* Add support for `pages` input option for multi-page input.
|
* Add support for `pages` input option for multi-page input.
|
||||||
[#1566](https://github.com/lovell/sharp/issues/1566)
|
[#1566](https://github.com/lovell/sharp/issues/1566)
|
||||||
|
|
||||||
|
* Allow Stream-based input of raw pixel data.
|
||||||
|
[#1579](https://github.com/lovell/sharp/issues/1579)
|
||||||
|
|
||||||
* Add support for `page` input option to GIF and PDF.
|
* Add support for `page` input option to GIF and PDF.
|
||||||
[#1595](https://github.com/lovell/sharp/pull/1595)
|
[#1595](https://github.com/lovell/sharp/pull/1595)
|
||||||
[@ramiel](https://github.com/ramiel)
|
[@ramiel](https://github.com/ramiel)
|
||||||
|
@ -19,6 +19,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
||||||
// Plain Object descriptor, e.g. create
|
// Plain Object descriptor, e.g. create
|
||||||
inputOptions = input;
|
inputOptions = input;
|
||||||
|
if (is.plainObject(inputOptions.raw)) {
|
||||||
|
// Raw Stream
|
||||||
|
inputDescriptor.buffer = [];
|
||||||
|
}
|
||||||
} else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
|
} else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||||
// Stream
|
// Stream
|
||||||
inputDescriptor.buffer = [];
|
inputDescriptor.buffer = [];
|
||||||
|
@ -92,6 +92,31 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('JPEG to raw Stream and back again', function (done) {
|
||||||
|
const width = 32;
|
||||||
|
const height = 24;
|
||||||
|
const writable = sharp({
|
||||||
|
raw: {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
channels: 3
|
||||||
|
}
|
||||||
|
});
|
||||||
|
writable
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(32, info.width);
|
||||||
|
assert.strictEqual(24, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(width, height)
|
||||||
|
.raw()
|
||||||
|
.pipe(writable);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Ouput raw, uncompressed image data', function () {
|
describe('Ouput raw, uncompressed image data', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user