🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

sharp

Package Overview
Dependencies
Maintainers
1
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sharp - npm Package Compare versions

Comparing version
0.34.3-rc.0
to
0.34.3-rc.1
+17
-7
lib/constructor.js

@@ -156,6 +156,2 @@ // Copyright 2013 Lovell Fuller and others.

* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
* @param {boolean} [options.jp2Oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.

@@ -168,2 +164,3 @@ * @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.

* to avoid sharp premultiplying the image. (optional, default `false`)
* @param {number} [options.raw.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `raw.height`.
* @param {Object} [options.create] - describes a new image to be created.

@@ -174,6 +171,7 @@ * @param {number} [options.create.width] - integral number of pixels wide.

* @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
* @param {number} [options.create.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `create.height`.
* @param {Object} [options.create.noise] - describes a noise to be created.
* @param {string} [options.create.noise.type] - type of generated noise, currently only `gaussian` is supported.
* @param {number} [options.create.noise.mean] - mean of pixels in generated noise.
* @param {number} [options.create.noise.sigma] - standard deviation of pixels in generated noise.
* @param {number} [options.create.noise.mean=128] - Mean value of pixels in the generated noise.
* @param {number} [options.create.noise.sigma=30] - Standard deviation of pixel values in the generated noise.
* @param {Object} [options.text] - describes a new text image to be created.

@@ -198,3 +196,13 @@ * @param {string} [options.text.text] - text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.

* @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
*
* @param {Object} [options.tiff] - Describes TIFF specific options.
* @param {number} [options.tiff.subifd=-1] - Sub Image File Directory to extract for OME-TIFF, defaults to main image.
* @param {Object} [options.svg] - Describes SVG specific options.
* @param {string} [options.svg.stylesheet] - Custom CSS for SVG input, applied with a User Origin during the CSS cascade.
* @param {boolean} [options.svg.highBitdepth=false] - Set to `true` to render SVG input at 32-bits per channel (128-bit) instead of 8-bits per channel (32-bit) RGBA.
* @param {Object} [options.pdf] - Describes PDF specific options. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
* @param {string|Object} [options.pdf.background] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
* @param {Object} [options.openSlide] - Describes OpenSlide specific options. Requires the use of a globally-installed libvips compiled with support for OpenSlide.
* @param {number} [options.openSlide.level=0] - Level to extract from a multi-level input, zero based.
* @param {Object} [options.jp2] - Describes JPEG 2000 specific options. Requires the use of a globally-installed libvips compiled with support for OpenJPEG.
* @param {boolean} [options.jp2.oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
* @returns {Sharp}

@@ -305,2 +313,3 @@ * @throws {Error} Invalid parameters

withExifMerge: true,
withXmp: '',
resolveWithObject: false,

@@ -346,2 +355,3 @@ loop: -1,

gifInterPaletteMaxError: 3,
gifKeepDuplicateFrames: false,
gifReuse: true,

@@ -348,0 +358,0 @@ gifProgressive: false,

@@ -25,2 +25,13 @@ // Copyright 2013 Lovell Fuller and others.

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', 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
];
/**

@@ -31,5 +42,7 @@ * Extract input options, if any, from an object.

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;

@@ -177,4 +190,2 @@ }

inputDescriptor.rawChannels = inputOptions.raw.channels;
inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
switch (input.constructor) {

@@ -213,2 +224,21 @@ case Uint8Array:

}
inputDescriptor.rawPremultiplied = false;
if (is.defined(inputOptions.raw.premultiplied)) {
if (is.bool(inputOptions.raw.premultiplied)) {
inputDescriptor.rawPremultiplied = inputOptions.raw.premultiplied;
} else {
throw is.invalidParameterError('raw.premultiplied', 'boolean', inputOptions.raw.premultiplied);
}
}
inputDescriptor.rawPageHeight = 0;
if (is.defined(inputOptions.raw.pageHeight)) {
if (is.integer(inputOptions.raw.pageHeight) && inputOptions.raw.pageHeight > 0 && inputOptions.raw.pageHeight <= inputOptions.raw.height) {
if (inputOptions.raw.height % inputOptions.raw.pageHeight !== 0) {
throw new Error(`Expected raw.height ${inputOptions.raw.height} to be a multiple of raw.pageHeight ${inputOptions.raw.pageHeight}`);
}
inputDescriptor.rawPageHeight = inputOptions.raw.pageHeight;
} else {
throw is.invalidParameterError('raw.pageHeight', 'positive integer', inputOptions.raw.pageHeight);
}
}
}

@@ -237,6 +267,13 @@ // Multi-page input (GIF, TIFF, PDF)

}
// Multi-level input (OpenSlide)
if (is.defined(inputOptions.level)) {
// OpenSlide specific options
if (is.object(inputOptions.openSlide) && is.defined(inputOptions.openSlide.level)) {
if (is.integer(inputOptions.openSlide.level) && is.inRange(inputOptions.openSlide.level, 0, 256)) {
inputDescriptor.openSlideLevel = inputOptions.openSlide.level;
} else {
throw is.invalidParameterError('openSlide.level', 'integer between 0 and 256', inputOptions.openSlide.level);
}
} else if (is.defined(inputOptions.level)) {
// Deprecated
if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) {
inputDescriptor.level = inputOptions.level;
inputDescriptor.openSlideLevel = inputOptions.level;
} else {

@@ -246,6 +283,13 @@ throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);

}
// Sub Image File Directory (TIFF)
if (is.defined(inputOptions.subifd)) {
// TIFF specific options
if (is.object(inputOptions.tiff) && is.defined(inputOptions.tiff.subifd)) {
if (is.integer(inputOptions.tiff.subifd) && is.inRange(inputOptions.tiff.subifd, -1, 100000)) {
inputDescriptor.tiffSubifd = inputOptions.tiff.subifd;
} else {
throw is.invalidParameterError('tiff.subifd', 'integer between -1 and 100000', inputOptions.tiff.subifd);
}
} else if (is.defined(inputOptions.subifd)) {
// Deprecated
if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) {
inputDescriptor.subifd = inputOptions.subifd;
inputDescriptor.tiffSubifd = inputOptions.subifd;
} else {

@@ -255,12 +299,32 @@ throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);

}
// PDF background colour
if (is.defined(inputOptions.pdfBackground)) {
// 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);
} else if (is.defined(inputOptions.pdfBackground)) {
// Deprecated
inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdfBackground);
}
// JP2 oneshot
if (is.defined(inputOptions.jp2Oneshot)) {
if (is.bool(inputOptions.jp2Oneshot)) {
inputDescriptor.jp2Oneshot = inputOptions.jp2Oneshot;
// JPEG 2000 specific options
if (is.object(inputOptions.jp2) && is.defined(inputOptions.jp2.oneshot)) {
if (is.bool(inputOptions.jp2.oneshot)) {
inputDescriptor.jp2Oneshot = inputOptions.jp2.oneshot;
} else {
throw is.invalidParameterError('jp2Oneshot', 'boolean', inputOptions.jp2Oneshot);
throw is.invalidParameterError('jp2.oneshot', 'boolean', inputOptions.jp2.oneshot);
}

@@ -279,2 +343,13 @@ }

inputDescriptor.createChannels = inputOptions.create.channels;
inputDescriptor.createPageHeight = 0;
if (is.defined(inputOptions.create.pageHeight)) {
if (is.integer(inputOptions.create.pageHeight) && inputOptions.create.pageHeight > 0 && inputOptions.create.pageHeight <= inputOptions.create.height) {
if (inputOptions.create.height % inputOptions.create.pageHeight !== 0) {
throw new Error(`Expected create.height ${inputOptions.create.height} to be a multiple of create.pageHeight ${inputOptions.create.pageHeight}`);
}
inputDescriptor.createPageHeight = inputOptions.create.pageHeight;
} else {
throw is.invalidParameterError('create.pageHeight', 'positive integer', inputOptions.create.pageHeight);
}
}
// Noise

@@ -285,18 +360,24 @@ if (is.defined(inputOptions.create.noise)) {

}
if (!is.inArray(inputOptions.create.noise.type, ['gaussian'])) {
if (inputOptions.create.noise.type !== 'gaussian') {
throw new Error('Only gaussian noise is supported at the moment');
}
inputDescriptor.createNoiseType = inputOptions.create.noise.type;
if (!is.inRange(inputOptions.create.channels, 1, 4)) {
throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);
}
inputDescriptor.createNoiseType = inputOptions.create.noise.type;
if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
} else {
throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
inputDescriptor.createNoiseMean = 128;
if (is.defined(inputOptions.create.noise.mean)) {
if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
} else {
throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
}
}
if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
} else {
throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
inputDescriptor.createNoiseSigma = 30;
if (is.defined(inputOptions.create.noise.sigma)) {
if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
} else {
throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
}
}

@@ -536,2 +617,3 @@ } else if (is.defined(inputOptions.create.background)) {

* - `xmp`: Buffer containing raw XMP data, if present
* - `xmpAsString`: String containing XMP data, if valid UTF-8.
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present

@@ -538,0 +620,0 @@ * - `formatMagick`: String containing format for images loaded via *magick

@@ -316,2 +316,55 @@ // Copyright 2013 Lovell Fuller and others.

/**
* Keep XMP metadata from the input image in the output image.
*
* @since 0.34.3
*
* @example
* const outputWithXmp = await sharp(inputWithXmp)
* .keepXmp()
* .toBuffer();
*
* @returns {Sharp}
*/
function keepXmp () {
this.options.keepMetadata |= 0b00010;
return this;
}
/**
* Set XMP metadata in the output image.
*
* Supported by PNG, JPEG, WebP, and TIFF output.
*
* @since 0.34.3
*
* @example
* const xmpString = `
* <?xml version="1.0"?>
* <x:xmpmeta xmlns:x="adobe:ns:meta/">
* <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
* <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
* <dc:creator><rdf:Seq><rdf:li>John Doe</rdf:li></rdf:Seq></dc:creator>
* </rdf:Description>
* </rdf:RDF>
* </x:xmpmeta>`;
*
* const data = await sharp(input)
* .withXmp(xmpString)
* .toBuffer();
*
* @param {string} xmp String containing XMP metadata to be embedded in the output image.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function withXmp (xmp) {
if (is.string(xmp) && xmp.length > 0) {
this.options.withXmp = xmp;
this.options.keepMetadata |= 0b00010;
} else {
throw is.invalidParameterError('xmp', 'non-empty string', xmp);
}
return this;
}
/**
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.

@@ -733,2 +786,3 @@ *

* @param {number} [options.interPaletteMaxError=3] - maximum inter-palette error for palette reuse, between 0 and 256
* @param {boolean} [options.keepDuplicateFrames=false] - keep duplicate frames in the output instead of combining them
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation

@@ -784,2 +838,9 @@ * @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)

}
if (is.defined(options.keepDuplicateFrames)) {
if (is.bool(options.keepDuplicateFrames)) {
this._setBooleanOption('gifKeepDuplicateFrames', options.keepDuplicateFrames);
} else {
throw is.invalidParameterError('keepDuplicateFrames', 'boolean', options.keepDuplicateFrames);
}
}
}

@@ -1574,2 +1635,4 @@ trySetAnimationOptions(options, this.options);

withIccProfile,
keepXmp,
withXmp,
keepMetadata,

@@ -1576,0 +1639,0 @@ withMetadata,

@@ -153,2 +153,4 @@ // Copyright 2013 Lovell Fuller and others.

* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
* - `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook.
* - `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version.
*

@@ -155,0 +157,0 @@ * When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.

@@ -138,12 +138,6 @@ // Copyright 2013 Lovell Fuller and others.

*
* The maximum number of images that sharp can process in parallel
* is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
* which defaults to 4.
* :::note
* Further {@link /performance|control over performance} is available.
* :::
*
* https://nodejs.org/api/cli.html#uv_threadpool_sizesize
*
* For example, by default, a machine with 8 CPU cores will process
* 4 images in parallel and use up to 8 threads per image,
* so there will be up to 32 concurrent threads.
*
* @example

@@ -150,0 +144,0 @@ * const threads = sharp.concurrency(); // 4

{
"name": "sharp",
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
"version": "0.34.3-rc.0",
"version": "0.34.3-rc.1",
"author": "Lovell Fuller <npm@lovell.info>",

@@ -144,35 +144,35 @@ "homepage": "https://sharp.pixelplumbing.com",

"optionalDependencies": {
"@img/sharp-darwin-arm64": "0.34.3-rc.0",
"@img/sharp-darwin-x64": "0.34.3-rc.0",
"@img/sharp-libvips-darwin-arm64": "1.2.0-rc.2",
"@img/sharp-libvips-darwin-x64": "1.2.0-rc.2",
"@img/sharp-libvips-linux-arm": "1.2.0-rc.2",
"@img/sharp-libvips-linux-arm64": "1.2.0-rc.2",
"@img/sharp-libvips-linux-ppc64": "1.2.0-rc.2",
"@img/sharp-libvips-linux-s390x": "1.2.0-rc.2",
"@img/sharp-libvips-linux-x64": "1.2.0-rc.2",
"@img/sharp-libvips-linuxmusl-arm64": "1.2.0-rc.2",
"@img/sharp-libvips-linuxmusl-x64": "1.2.0-rc.2",
"@img/sharp-linux-arm": "0.34.3-rc.0",
"@img/sharp-linux-arm64": "0.34.3-rc.0",
"@img/sharp-linux-ppc64": "0.34.3-rc.0",
"@img/sharp-linux-s390x": "0.34.3-rc.0",
"@img/sharp-linux-x64": "0.34.3-rc.0",
"@img/sharp-linuxmusl-arm64": "0.34.3-rc.0",
"@img/sharp-linuxmusl-x64": "0.34.3-rc.0",
"@img/sharp-wasm32": "0.34.3-rc.0",
"@img/sharp-win32-arm64": "0.34.3-rc.0",
"@img/sharp-win32-ia32": "0.34.3-rc.0",
"@img/sharp-win32-x64": "0.34.3-rc.0"
"@img/sharp-darwin-arm64": "0.34.3-rc.1",
"@img/sharp-darwin-x64": "0.34.3-rc.1",
"@img/sharp-libvips-darwin-arm64": "1.2.0",
"@img/sharp-libvips-darwin-x64": "1.2.0",
"@img/sharp-libvips-linux-arm": "1.2.0",
"@img/sharp-libvips-linux-arm64": "1.2.0",
"@img/sharp-libvips-linux-ppc64": "1.2.0",
"@img/sharp-libvips-linux-s390x": "1.2.0",
"@img/sharp-libvips-linux-x64": "1.2.0",
"@img/sharp-libvips-linuxmusl-arm64": "1.2.0",
"@img/sharp-libvips-linuxmusl-x64": "1.2.0",
"@img/sharp-linux-arm": "0.34.3-rc.1",
"@img/sharp-linux-arm64": "0.34.3-rc.1",
"@img/sharp-linux-ppc64": "0.34.3-rc.1",
"@img/sharp-linux-s390x": "0.34.3-rc.1",
"@img/sharp-linux-x64": "0.34.3-rc.1",
"@img/sharp-linuxmusl-arm64": "0.34.3-rc.1",
"@img/sharp-linuxmusl-x64": "0.34.3-rc.1",
"@img/sharp-wasm32": "0.34.3-rc.1",
"@img/sharp-win32-arm64": "0.34.3-rc.1",
"@img/sharp-win32-ia32": "0.34.3-rc.1",
"@img/sharp-win32-x64": "0.34.3-rc.1"
},
"devDependencies": {
"@emnapi/runtime": "^1.4.3",
"@img/sharp-libvips-dev": "1.2.0-rc.2",
"@img/sharp-libvips-dev-wasm32": "1.2.0-rc.2",
"@img/sharp-libvips-win32-arm64": "1.2.0-rc.2",
"@img/sharp-libvips-win32-ia32": "1.2.0-rc.2",
"@img/sharp-libvips-win32-x64": "1.2.0-rc.2",
"@emnapi/runtime": "^1.4.4",
"@img/sharp-libvips-dev": "1.2.0",
"@img/sharp-libvips-dev-wasm32": "1.2.0",
"@img/sharp-libvips-win32-arm64": "1.2.0",
"@img/sharp-libvips-win32-ia32": "1.2.0",
"@img/sharp-libvips-win32-x64": "1.2.0",
"@types/node": "*",
"cc": "^3.0.1",
"emnapi": "^1.4.3",
"emnapi": "^1.4.4",
"exif-reader": "^2.0.2",

@@ -183,8 +183,8 @@ "extract-zip": "^2.0.1",

"license-checker": "^25.0.1",
"mocha": "^11.6.0",
"node-addon-api": "^8.3.1",
"mocha": "^11.7.1",
"node-addon-api": "^8.4.0",
"node-gyp": "^11.2.0",
"nyc": "^17.1.0",
"semistandard": "^17.0.0",
"tar-fs": "^3.0.9",
"tar-fs": "^3.1.0",
"tsd": "^0.32.0"

@@ -197,3 +197,3 @@ },

"config": {
"libvips": ">=8.17.0"
"libvips": ">=8.17.1"
},

@@ -200,0 +200,0 @@ "funding": {

@@ -96,2 +96,3 @@ // Copyright 2013 Lovell Fuller and others.

descriptor->rawPremultiplied = AttrAsBool(input, "rawPremultiplied");
descriptor->rawPageHeight = AttrAsUint32(input, "rawPageHeight");
}

@@ -105,9 +106,16 @@ // Multi-page input (GIF, TIFF, PDF)

}
// SVG
if (HasAttr(input, "svgStylesheet")) {
descriptor->svgStylesheet = AttrAsStr(input, "svgStylesheet");
}
if (HasAttr(input, "svgHighBitdepth")) {
descriptor->svgHighBitdepth = AttrAsBool(input, "svgHighBitdepth");
}
// Multi-level input (OpenSlide)
if (HasAttr(input, "level")) {
descriptor->level = AttrAsUint32(input, "level");
if (HasAttr(input, "openSlideLevel")) {
descriptor->openSlideLevel = AttrAsUint32(input, "openSlideLevel");
}
// subIFD (OME-TIFF)
if (HasAttr(input, "subifd")) {
descriptor->subifd = AttrAsInt32(input, "subifd");
descriptor->tiffSubifd = AttrAsInt32(input, "tiffSubifd");
}

@@ -127,2 +135,3 @@ // // PDF background color

descriptor->createHeight = AttrAsUint32(input, "createHeight");
descriptor->createPageHeight = AttrAsUint32(input, "createPageHeight");
if (HasAttr(input, "createNoiseType")) {

@@ -281,2 +290,3 @@ descriptor->createNoiseType = AttrAsStr(input, "createNoiseType");

case ImageType::RAD: id = "rad"; break;
case ImageType::DCRAW: id = "dcraw"; break;
case ImageType::VIPS: id = "vips"; break;

@@ -330,2 +340,4 @@ case ImageType::RAW: id = "raw"; break;

{ "VipsForeignLoadRadBuffer", ImageType::RAD },
{ "VipsForeignLoadDcRawFile", ImageType::DCRAW },
{ "VipsForeignLoadDcRawBuffer", ImageType::DCRAW },
{ "VipsForeignLoadVips", ImageType::VIPS },

@@ -396,2 +408,44 @@ { "VipsForeignLoadVipsFile", ImageType::VIPS },

/*
Format-specific options builder
*/
vips::VOption* GetOptionsForImageType(ImageType imageType, InputDescriptor *descriptor) {
vips::VOption *option = VImage::option()
->set("access", descriptor->access)
->set("fail_on", descriptor->failOn);
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
option->set("unlimited", true);
}
if (ImageTypeSupportsPage(imageType)) {
option->set("n", descriptor->pages);
option->set("page", descriptor->page);
}
switch (imageType) {
case ImageType::SVG:
option->set("dpi", descriptor->density)
->set("stylesheet", descriptor->svgStylesheet.data())
->set("high_bitdepth", descriptor->svgHighBitdepth);
break;
case ImageType::TIFF:
option->set("tiffSubifd", descriptor->tiffSubifd);
break;
case ImageType::PDF:
option->set("dpi", descriptor->density)
->set("background", descriptor->pdfBackground);
break;
case ImageType::OPENSLIDE:
option->set("openSlideLevel", descriptor->openSlideLevel);
break;
case ImageType::JP2:
option->set("oneshot", descriptor->jp2Oneshot);
break;
case ImageType::MAGICK:
option->set("density", std::to_string(descriptor->density).data());
break;
default:
break;
}
return option;
}
/*
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)

@@ -413,2 +467,6 @@ */

}
if (descriptor->rawPageHeight > 0) {
image.set(VIPS_META_PAGE_HEIGHT, descriptor->rawPageHeight);
image.set(VIPS_META_N_PAGES, static_cast<int>(descriptor->rawHeight / descriptor->rawPageHeight));
}
if (descriptor->rawPremultiplied) {

@@ -423,30 +481,3 @@ image = image.unpremultiply();

try {
vips::VOption *option = VImage::option()
->set("access", descriptor->access)
->set("fail_on", descriptor->failOn);
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
option->set("unlimited", true);
}
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
option->set("dpi", descriptor->density);
}
if (imageType == ImageType::MAGICK) {
option->set("density", std::to_string(descriptor->density).data());
}
if (ImageTypeSupportsPage(imageType)) {
option->set("n", descriptor->pages);
option->set("page", descriptor->page);
}
if (imageType == ImageType::OPENSLIDE) {
option->set("level", descriptor->level);
}
if (imageType == ImageType::TIFF) {
option->set("subifd", descriptor->subifd);
}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
if (imageType == ImageType::JP2) {
option->set("oneshot", descriptor->jp2Oneshot);
}
vips::VOption *option = GetOptionsForImageType(imageType, descriptor);
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);

@@ -491,2 +522,6 @@ if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {

}
if (descriptor->createPageHeight > 0) {
image.set(VIPS_META_PAGE_HEIGHT, descriptor->createPageHeight);
image.set(VIPS_META_N_PAGES, static_cast<int>(descriptor->createHeight / descriptor->createPageHeight));
}
image = image.cast(VIPS_FORMAT_UCHAR);

@@ -535,30 +570,3 @@ imageType = ImageType::RAW;

try {
vips::VOption *option = VImage::option()
->set("access", descriptor->access)
->set("fail_on", descriptor->failOn);
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
option->set("unlimited", true);
}
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
option->set("dpi", descriptor->density);
}
if (imageType == ImageType::MAGICK) {
option->set("density", std::to_string(descriptor->density).data());
}
if (ImageTypeSupportsPage(imageType)) {
option->set("n", descriptor->pages);
option->set("page", descriptor->page);
}
if (imageType == ImageType::OPENSLIDE) {
option->set("level", descriptor->level);
}
if (imageType == ImageType::TIFF) {
option->set("subifd", descriptor->subifd);
}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
if (imageType == ImageType::JP2) {
option->set("oneshot", descriptor->jp2Oneshot);
}
vips::VOption *option = GetOptionsForImageType(imageType, descriptor);
image = VImage::new_from_file(descriptor->file.data(), option);

@@ -565,0 +573,0 @@ if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {

@@ -19,4 +19,4 @@ // Copyright 2013 Lovell Fuller and others.

(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 17) || \
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 17 && VIPS_MICRO_VERSION < 0)
#error "libvips version 8.17.0+ is required - please see https://sharp.pixelplumbing.com/install"
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 17 && VIPS_MICRO_VERSION < 1)
#error "libvips version 8.17.1+ is required - please see https://sharp.pixelplumbing.com/install"
#endif

@@ -52,9 +52,9 @@

bool rawPremultiplied;
int rawPageHeight;
int pages;
int page;
int level;
int subifd;
int createChannels;
int createWidth;
int createHeight;
int createPageHeight;
std::vector<double> createBackground;

@@ -82,2 +82,6 @@ std::string createNoiseType;

VipsAlign joinValign;
std::string svgStylesheet;
bool svgHighBitdepth;
int tiffSubifd;
int openSlideLevel;
std::vector<double> pdfBackground;

@@ -102,9 +106,9 @@ bool jp2Oneshot;

rawPremultiplied(false),
rawPageHeight(0),
pages(1),
page(0),
level(0),
subifd(-1),
createChannels(0),
createWidth(0),
createHeight(0),
createPageHeight(0),
createBackground{ 0.0, 0.0, 0.0, 255.0 },

@@ -128,2 +132,5 @@ createNoiseMean(0.0),

joinValign(VIPS_ALIGN_LOW),
svgHighBitdepth(false),
tiffSubifd(-1),
openSlideLevel(0),
pdfBackground{ 255.0, 255.0, 255.0, 255.0 },

@@ -170,2 +177,3 @@ jp2Oneshot(false) {}

RAD,
DCRAW,
VIPS,

@@ -227,12 +235,7 @@ RAW,

/*
Does this image type support multiple pages?
Format-specific options builder
*/
bool ImageTypeSupportsPage(ImageType imageType);
vips::VOption* GetOptionsForImageType(ImageType imageType, InputDescriptor *descriptor);
/*
Does this image type support removal of safety limits?
*/
bool ImageTypeSupportsUnlimited(ImageType imageType);
/*
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)

@@ -239,0 +242,0 @@ */

@@ -265,2 +265,6 @@ // Copyright 2013 Lovell Fuller and others.

info.Set("xmp", Napi::Buffer<char>::NewOrCopy(env, baton->xmp, baton->xmpLength, sharp::FreeCallback));
if (g_utf8_validate(static_cast<char const *>(baton->xmp), baton->xmpLength, nullptr)) {
info.Set("xmpAsString",
Napi::String::New(env, static_cast<char const *>(baton->xmp), baton->xmpLength));
}
}

@@ -267,0 +271,0 @@ if (baton->tifftagPhotoshopLength > 0) {

@@ -172,2 +172,3 @@ // Copyright 2013 Lovell Fuller and others.

double gifInterPaletteMaxError;
bool gifKeepDuplicateFrames;
bool gifReuse;

@@ -205,2 +206,3 @@ bool gifProgressive;

bool withExifMerge;
std::string withXmp;
int timeoutSeconds;

@@ -347,2 +349,3 @@ std::vector<double> convKernel;

gifInterPaletteMaxError(3.0),
gifKeepDuplicateFrames(false),
gifReuse(true),

@@ -349,0 +352,0 @@ gifProgressive(false),

@@ -122,3 +122,3 @@ // Copyright 2013 Lovell Fuller and others.

"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad"
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad", "dcraw"
}) {

@@ -125,0 +125,0 @@ // Input

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display