mirror of
https://github.com/lovell/sharp.git
synced 2025-12-18 23:05:04 +01:00
Expose stylesheet and highBitdepth SVG input params
This commit is contained in:
36
lib/input.js
36
lib/input.js
@@ -22,14 +22,27 @@ const align = {
|
||||
high: 'high'
|
||||
};
|
||||
|
||||
const inputStreamParameters = [
|
||||
// Limits and error handling
|
||||
'failOn', 'limitInputPixels', 'unlimited',
|
||||
// Format-generic
|
||||
'animated', 'autoOrient', 'density', 'ignoreIcc', 'page', 'pages', 'sequentialRead',
|
||||
// Format-specific
|
||||
'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff',
|
||||
// Deprecated
|
||||
'failOnError', 'level', 'pdfBackground', 'subifd'
|
||||
];
|
||||
|
||||
/**
|
||||
* Extract input options, if any, from an object.
|
||||
* @private
|
||||
*/
|
||||
function _inputOptionsFromObject (obj) {
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot }
|
||||
const params = inputStreamParameters
|
||||
.filter(p => is.defined(obj[p]))
|
||||
.map(p => ([p, obj[p]]));
|
||||
return params.length
|
||||
? Object.fromEntries(params)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -260,6 +273,23 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
||||
}
|
||||
}
|
||||
// SVG specific options
|
||||
if (is.object(inputOptions.svg)) {
|
||||
if (is.defined(inputOptions.svg.stylesheet)) {
|
||||
if (is.string(inputOptions.svg.stylesheet)) {
|
||||
inputDescriptor.svgStylesheet = inputOptions.svg.stylesheet;
|
||||
} else {
|
||||
throw is.invalidParameterError('svg.stylesheet', 'string', inputOptions.svg.stylesheet);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.svg.highBitdepth)) {
|
||||
if (is.bool(inputOptions.svg.highBitdepth)) {
|
||||
inputDescriptor.svgHighBitdepth = inputOptions.svg.highBitdepth;
|
||||
} else {
|
||||
throw is.invalidParameterError('svg.highBitdepth', 'boolean', inputOptions.svg.highBitdepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
// PDF specific options
|
||||
if (is.object(inputOptions.pdf) && is.defined(inputOptions.pdf.background)) {
|
||||
inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdf.background);
|
||||
|
||||
Reference in New Issue
Block a user