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
|
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
|
### v0.25.1 - 7th March 2020
|
||||||
|
|
||||||
* Ensure prebuilt binaries are fetched based on N-API version.
|
* Ensure prebuilt binaries are fetched based on N-API version.
|
||||||
|
@ -100,10 +100,7 @@ function composite (images) {
|
|||||||
if (!is.object(image)) {
|
if (!is.object(image)) {
|
||||||
throw is.invalidParameterError('image to composite', 'object', image);
|
throw is.invalidParameterError('image to composite', 'object', image);
|
||||||
}
|
}
|
||||||
const { raw, density, limitInputPixels, sequentialRead } = image;
|
const inputOptions = this._inputOptionsFromObject(image);
|
||||||
const inputOptions = [raw, density, limitInputPixels, sequentialRead].some(is.defined)
|
|
||||||
? { raw, density, limitInputPixels, sequentialRead }
|
|
||||||
: undefined;
|
|
||||||
const composite = {
|
const composite = {
|
||||||
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
||||||
blend: 'over',
|
blend: 'over',
|
||||||
|
18
lib/input.js
18
lib/input.js
@ -4,6 +4,17 @@ const color = require('color');
|
|||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
const sharp = require('../build/Release/sharp.node');
|
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.
|
* Create Object containing input and input-related options.
|
||||||
* @private
|
* @private
|
||||||
@ -23,12 +34,12 @@ 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) || is.bool(inputOptions.failOnError)) {
|
if (_inputOptionsFromObject(inputOptions)) {
|
||||||
// Raw Stream
|
// Stream with options
|
||||||
inputDescriptor.buffer = [];
|
inputDescriptor.buffer = [];
|
||||||
}
|
}
|
||||||
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||||
// Stream
|
// Stream without options
|
||||||
inputDescriptor.buffer = [];
|
inputDescriptor.buffer = [];
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
||||||
@ -337,6 +348,7 @@ function stats (callback) {
|
|||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
Object.assign(Sharp.prototype, {
|
Object.assign(Sharp.prototype, {
|
||||||
// Private
|
// Private
|
||||||
|
_inputOptionsFromObject,
|
||||||
_createInputDescriptor,
|
_createInputDescriptor,
|
||||||
_write,
|
_write,
|
||||||
_flattenBufferIn,
|
_flattenBufferIn,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user