diff --git a/docs/changelog.md b/docs/changelog.md index 83735936..2ca4272b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.9.1 +### v0.25.2 - TBD + +* Ensure input options are consistently and correctly detected. + [#2118](https://github.com/lovell/sharp/issues/2118) + ### v0.25.1 - 7th March 2020 * Ensure prebuilt binaries are fetched based on N-API version. diff --git a/lib/composite.js b/lib/composite.js index 42f9f28d..0e518036 100644 --- a/lib/composite.js +++ b/lib/composite.js @@ -100,10 +100,7 @@ function composite (images) { if (!is.object(image)) { throw is.invalidParameterError('image to composite', 'object', image); } - const { raw, density, limitInputPixels, sequentialRead } = image; - const inputOptions = [raw, density, limitInputPixels, sequentialRead].some(is.defined) - ? { raw, density, limitInputPixels, sequentialRead } - : undefined; + const inputOptions = this._inputOptionsFromObject(image); const composite = { input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }), blend: 'over', diff --git a/lib/input.js b/lib/input.js index f0a6d93f..e1eb48ae 100644 --- a/lib/input.js +++ b/lib/input.js @@ -4,6 +4,17 @@ const color = require('color'); const is = require('./is'); const sharp = require('../build/Release/sharp.node'); +/** + * Extract input options, if any, from an object. + * @private + */ +function _inputOptionsFromObject (obj) { + const { raw, density, limitInputPixels, sequentialRead, failOnError } = obj; + return [raw, density, limitInputPixels, sequentialRead, failOnError].some(is.defined) + ? { raw, density, limitInputPixels, sequentialRead, failOnError } + : undefined; +} + /** * Create Object containing input and input-related options. * @private @@ -23,12 +34,12 @@ function _createInputDescriptor (input, inputOptions, containerOptions) { } else if (is.plainObject(input) && !is.defined(inputOptions)) { // Plain Object descriptor, e.g. create inputOptions = input; - if (is.plainObject(inputOptions.raw) || is.bool(inputOptions.failOnError)) { - // Raw Stream + if (_inputOptionsFromObject(inputOptions)) { + // Stream with options inputDescriptor.buffer = []; } } else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) { - // Stream + // Stream without options inputDescriptor.buffer = []; } else { throw new Error(`Unsupported input '${input}' of type ${typeof input}${ @@ -337,6 +348,7 @@ function stats (callback) { module.exports = function (Sharp) { Object.assign(Sharp.prototype, { // Private + _inputOptionsFromObject, _createInputDescriptor, _write, _flattenBufferIn,