mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Ensure consistent, correct detection of input opts #2118
This commit is contained in:
parent
24285bb0e0
commit
4894c10dd9
@ -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.
|
||||
|
@ -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',
|
||||
|
18
lib/input.js
18
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user