mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Add failOnError option to fail-fast on bad input image data (#976)
This commit is contained in:
committed by
Lovell Fuller
parent
382d476271
commit
b4d72bd544
@@ -93,6 +93,9 @@ const debuglog = util.debuglog('sharp');
|
||||
* a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||
* @param {Boolean} [options.failOnError=false] - by default apply a "best effort"
|
||||
* to decode images, even if the data is corrupt or invalid. Set this flag to true
|
||||
* if you'd rather halt processing and raise an error when loading invalid images.
|
||||
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
|
||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||
* @param {Number} [options.raw.width]
|
||||
|
||||
10
lib/input.js
10
lib/input.js
@@ -9,7 +9,7 @@ const sharp = require('../build/Release/sharp.node');
|
||||
* @private
|
||||
*/
|
||||
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
const inputDescriptor = {};
|
||||
const inputDescriptor = { failOnError: false };
|
||||
if (is.string(input)) {
|
||||
// filesystem
|
||||
inputDescriptor.file = input;
|
||||
@@ -26,6 +26,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
throw new Error('Unsupported input ' + typeof input);
|
||||
}
|
||||
if (is.object(inputOptions)) {
|
||||
// Fail on error
|
||||
if (is.defined(inputOptions.failOnError)) {
|
||||
if (is.bool(inputOptions.failOnError)) {
|
||||
inputDescriptor.failOnError = inputOptions.failOnError;
|
||||
} else {
|
||||
throw new Error('Invalid failOnError (boolean) ' + inputOptions.failOnError);
|
||||
}
|
||||
}
|
||||
// Density
|
||||
if (is.defined(inputOptions.density)) {
|
||||
if (is.integer(inputOptions.density) && is.inRange(inputOptions.density, 1, 2400)) {
|
||||
|
||||
Reference in New Issue
Block a user