🚀 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.33.5
to
0.34.0-rc.0
+2
-1
lib/channel.js

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

/**
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
* Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
*

@@ -162,2 +162,3 @@ * See also {@link /api-operation#flatten|flatten}.

* Decorate the Sharp prototype with channel-related functions.
* @module Sharp
* @private

@@ -164,0 +165,0 @@ */

@@ -42,5 +42,5 @@ // Copyright 2013 Lovell Fuller and others.

* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
* which will produce an output image containing one color channel.
* which will produce an output image containing one colour channel.
* An alpha channel may be present, and will be unchanged by the operation.

@@ -163,2 +163,3 @@ *

* Decorate the Sharp prototype with colour-related functions.
* @module Sharp
* @private

@@ -165,0 +166,0 @@ */

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

*
* Any resize, rotate or extract operations in the same processing pipeline
* will always be applied to the input image before composition.
* Other operations in the same processing pipeline (e.g. resize, rotate, flip,
* flop, extract) will always be applied to the input image before composition.
*

@@ -114,2 +114,3 @@ * The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,

* @param {number} [images[].input.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
* @param {Boolean} [images[].autoOrient=false] - set to true to use EXIF orientation data, if present, to orient the image.
* @param {String} [images[].blend='over'] - how to blend this image with the image below.

@@ -207,2 +208,3 @@ * @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.

* Decorate the Sharp prototype with composite-related functions.
* @module Sharp
* @private

@@ -209,0 +211,0 @@ */

@@ -124,6 +124,21 @@ // Copyright 2013 Lovell Fuller and others.

*
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
* @example
* // Join four input images as a 2x2 grid with a 4 pixel gutter
* const data = await sharp(
* [image1, image2, image3, image4],
* { join: { across: 2, shim: 4 } }
* ).toBuffer();
*
* @example
* // Generate a two-frame animated image from emoji
* const images = ['😀', '😛'].map(text => ({
* text: { text, width: 64, height: 64, channels: 4, rgba: true }
* }));
* await sharp(images, { join: { animated: true } }).toFile('out.gif');
*
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string|Array)} [input] - if present, can be
* a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
* a TypedArray containing raw pixel image data, or
* a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
* An array of inputs can be provided, and these will be joined together.
* JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.

@@ -136,2 +151,3 @@ * @param {Object} [options] - if present, is an Object with optional attributes.

* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
* @param {boolean} [options.autoOrient=false] - Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any.
* @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.

@@ -144,2 +160,3 @@ * @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.

* @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.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.

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

* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'.
* @param {Object} [options.join] - describes how an array of input images should be joined.
* @param {number} [options.join.across=1] - number of images to join horizontally.
* @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image.
* @param {number} [options.join.shim=0] - number of pixels to insert between joined images.
* @param {string|Object} [options.join.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
* @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).
* @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
*
* @returns {Sharp}

@@ -200,3 +225,2 @@ * @throws {Error} Invalid parameters

resizeBackground: [0, 0, 0, 255],
useExifOrientation: false,
angle: 0,

@@ -307,2 +331,3 @@ rotationAngle: 0,

webpSmartSubsample: false,
webpSmartDeblock: false,
webpPreset: 'default',

@@ -357,2 +382,3 @@ webpEffort: 4,

linearB: [],
pdfBackground: [255, 255, 255, 255],
// Function to notify of libvips warnings

@@ -457,4 +483,5 @@ debuglog: warning => {

* Export constructor.
* @module Sharp
* @private
*/
module.exports = Sharp;

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

/**
* Justication alignment
* Justification alignment
* @member

@@ -18,5 +18,9 @@ * @private

left: 'low',
top: 'low',
low: 'low',
center: 'centre',
centre: 'centre',
right: 'high'
right: 'high',
bottom: 'high',
high: 'high'
};

@@ -29,5 +33,5 @@

function _inputOptionsFromObject (obj) {
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd } = obj;
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd].some(is.defined)
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient } = obj;
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient].some(is.defined)
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient }
: undefined;

@@ -42,2 +46,3 @@ }

const inputDescriptor = {
autoOrient: false,
failOn: 'warning',

@@ -78,2 +83,14 @@ limitInputPixels: Math.pow(0x3FFF, 2),

inputDescriptor.buffer = [];
} else if (Array.isArray(input)) {
if (input.length > 1) {
// Join images together
if (!this.options.joining) {
this.options.joining = true;
this.options.join = input.map(i => this._createInputDescriptor(i));
} else {
throw new Error('Recursive join is unsupported');
}
} else {
throw new Error('Expected at least two images to join');
}
} else {

@@ -101,2 +118,10 @@ throw new Error(`Unsupported input '${input}' of type ${typeof input}${

}
// autoOrient
if (is.defined(inputOptions.autoOrient)) {
if (is.bool(inputOptions.autoOrient)) {
inputDescriptor.autoOrient = inputOptions.autoOrient;
} else {
throw is.invalidParameterError('autoOrient', 'boolean', inputOptions.autoOrient);
}
}
// Density

@@ -231,2 +256,6 @@ if (is.defined(inputOptions.density)) {

}
// PDF background colour
if (is.defined(inputOptions.pdfBackground)) {
this._setBackgroundColourOption('pdfBackground', inputOptions.pdfBackground);
}
// Create new image

@@ -366,2 +395,53 @@ if (is.defined(inputOptions.create)) {

}
// Join images together
if (is.defined(inputOptions.join)) {
if (is.defined(this.options.join)) {
if (is.defined(inputOptions.join.animated)) {
if (is.bool(inputOptions.join.animated)) {
inputDescriptor.joinAnimated = inputOptions.join.animated;
} else {
throw is.invalidParameterError('join.animated', 'boolean', inputOptions.join.animated);
}
}
if (is.defined(inputOptions.join.across)) {
if (is.integer(inputOptions.join.across) && is.inRange(inputOptions.join.across, 1, 1000000)) {
inputDescriptor.joinAcross = inputOptions.join.across;
} else {
throw is.invalidParameterError('join.across', 'integer between 1 and 100000', inputOptions.join.across);
}
}
if (is.defined(inputOptions.join.shim)) {
if (is.integer(inputOptions.join.shim) && is.inRange(inputOptions.join.shim, 0, 1000000)) {
inputDescriptor.joinShim = inputOptions.join.shim;
} else {
throw is.invalidParameterError('join.shim', 'integer between 0 and 100000', inputOptions.join.shim);
}
}
if (is.defined(inputOptions.join.background)) {
const background = color(inputOptions.join.background);
inputDescriptor.joinBackground = [
background.red(),
background.green(),
background.blue(),
Math.round(background.alpha() * 255)
];
}
if (is.defined(inputOptions.join.halign)) {
if (is.string(inputOptions.join.halign) && is.string(this.constructor.align[inputOptions.join.halign])) {
inputDescriptor.joinHalign = this.constructor.align[inputOptions.join.halign];
} else {
throw is.invalidParameterError('join.halign', 'valid alignment', inputOptions.join.halign);
}
}
if (is.defined(inputOptions.join.valign)) {
if (is.string(inputOptions.join.valign) && is.string(this.constructor.align[inputOptions.join.valign])) {
inputDescriptor.joinValign = this.constructor.align[inputOptions.join.valign];
} else {
throw is.invalidParameterError('join.valign', 'valid alignment', inputOptions.join.valign);
}
}
} else {
throw new Error('Expected input to be an array of images to join');
}
}
} else if (is.defined(inputOptions)) {

@@ -441,5 +521,6 @@ throw new Error('Invalid input options ' + inputOptions);

* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
* - `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
* - `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.

@@ -450,3 +531,3 @@ * - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.

* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)

@@ -483,12 +564,6 @@ * - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present

* @example
* // Based on EXIF rotation metadata, get the right-side-up width and height:
* // Get dimensions taking EXIF Orientation into account.
* const { autoOrient } = await sharp(input).metadata();
* const { width, height } = autoOrient;
*
* const size = getNormalSize(await sharp(input).metadata());
*
* function getNormalSize({ width, height, orientation }) {
* return (orientation || 0) >= 5
* ? { width: height, height: width }
* : { width, height };
* }
*
* @param {Function} [callback] - called with the arguments `(err, metadata)`

@@ -653,2 +728,3 @@ * @returns {Promise<Object>|Sharp}

* Decorate the Sharp prototype with input-related functions.
* @module Sharp
* @private

@@ -655,0 +731,0 @@ */

@@ -21,6 +21,5 @@ // Copyright 2013 Lovell Fuller and others.

/**
* Rotate the output image by either an explicit angle
* or auto-orient based on the EXIF `Orientation` tag.
* Rotate the output image.
*
* If an angle is provided, it is converted to a valid positive degree rotation.
* The provided angle is converted to a valid positive degree rotation.
* For example, `-450` will produce a 270 degree rotation.

@@ -31,10 +30,8 @@ *

*
* If no angle is provided, it is determined from the EXIF data.
* Mirroring is supported and may infer the use of a flip operation.
* For backwards compatibility, if no angle is provided, `.autoOrient()` will be called.
*
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
* Only one rotation can occur per pipeline (aside from an initial call without
* arguments to orient via EXIF data). Previous calls to `rotate` in the same
* pipeline will be ignored.
*
* Only one rotation can occur per pipeline.
* Previous calls to `rotate` in the same pipeline will be ignored.
*
* Multi-page images can only be rotated by 180 degrees.

@@ -46,13 +43,2 @@ *

* @example
* const pipeline = sharp()
* .rotate()
* .resize(null, 200)
* .toBuffer(function (err, outputBuffer, info) {
* // outputBuffer contains 200px high JPEG image data,
* // auto-rotated using EXIF Orientation tag
* // info.width and info.height contain the dimensions of the resized image
* });
* readableStream.pipe(pipeline);
*
* @example
* const rotateThenResize = await sharp(input)

@@ -74,8 +60,11 @@ * .rotate(90)

function rotate (angle, options) {
if (this.options.useExifOrientation || this.options.angle || this.options.rotationAngle) {
if (!is.defined(angle)) {
return this.autoOrient();
}
if (this.options.angle || this.options.rotationAngle) {
this.options.debuglog('ignoring previous rotate options');
this.options.angle = 0;
this.options.rotationAngle = 0;
}
if (!is.defined(angle)) {
this.options.useExifOrientation = true;
} else if (is.integer(angle) && !(angle % 90)) {
if (is.integer(angle) && !(angle % 90)) {
this.options.angle = angle;

@@ -100,2 +89,30 @@ } else if (is.number(angle)) {

/**
* Auto-orient based on the EXIF `Orientation` tag, then remove the tag.
* Mirroring is supported and may infer the use of a flip operation.
*
* Previous or subsequent use of `rotate(angle)` and either `flip()` or `flop()`
* will logically occur after auto-orientation, regardless of call order.
*
* @example
* const output = await sharp(input).autoOrient().toBuffer();
*
* @example
* const pipeline = sharp()
* .autoOrient()
* .resize(null, 200)
* .toBuffer(function (err, outputBuffer, info) {
* // outputBuffer contains 200px high JPEG image data,
* // auto-oriented using EXIF Orientation tag
* // info.width and info.height contain the dimensions of the resized image
* });
* readableStream.pipe(pipeline);
*
* @returns {Sharp}
*/
function autoOrient () {
this.options.input.autoOrient = true;
return this;
}
/**
* Mirror the image vertically (up-down) about the x-axis.

@@ -136,3 +153,3 @@ * This always occurs before rotation, if any.

* You must provide an array of length 4 or a 2x2 affine transformation matrix.
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.

@@ -939,2 +956,3 @@ *

* Decorate the Sharp prototype with operation-related functions.
* @module Sharp
* @private

@@ -944,2 +962,3 @@ */

Object.assign(Sharp.prototype, {
autoOrient,
rotate,

@@ -946,0 +965,0 @@ flip,

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

* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
* @param {boolean} [options.smartDeblock=false] - auto-adjust the deblocking filter, can improve low contrast edges (slow)
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text

@@ -662,2 +663,5 @@ * @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)

}
if (is.defined(options.smartDeblock)) {
this._setBooleanOption('webpSmartDeblock', options.smartDeblock);
}
if (is.defined(options.preset)) {

@@ -1128,4 +1132,2 @@ if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {

*
* Image metadata (EXIF, XMP) is unsupported.
*
* @since 0.31.3

@@ -1138,3 +1140,5 @@ *

* @param {boolean} [options.lossless=false] - use lossless compression
* @param {number} [options.effort=7] - CPU effort, between 3 (fastest) and 9 (slowest)
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
* @returns {Sharp}

@@ -1176,9 +1180,10 @@ * @throws {Error} Invalid options

if (is.defined(options.effort)) {
if (is.integer(options.effort) && is.inRange(options.effort, 3, 9)) {
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
this.options.jxlEffort = options.effort;
} else {
throw is.invalidParameterError('effort', 'integer between 3 and 9', options.effort);
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
}
}
}
trySetAnimationOptions(options, this.options);
return this._updateFormatOut('jxl', options);

@@ -1235,6 +1240,2 @@ }

*
* Requires libvips compiled with support for libgsf.
* The prebuilt binaries do not include this - see
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
*
* @example

@@ -1560,2 +1561,3 @@ * sharp('input.tiff')

* Decorate the Sharp prototype with output-related functions.
* @module Sharp
* @private

@@ -1562,0 +1564,0 @@ */

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

lanczos2: 'lanczos2',
lanczos3: 'lanczos3'
lanczos3: 'lanczos3',
mks2013: 'mks2013',
mks2021: 'mks2021'
};

@@ -109,3 +111,3 @@

function isRotationExpected (options) {
return (options.angle % 360) !== 0 || options.useExifOrientation === true || options.rotationAngle !== 0;
return (options.angle % 360) !== 0 || options.input.autoOrient === true || options.rotationAngle !== 0;
}

@@ -574,2 +576,3 @@

* Decorate the Sharp prototype with resize-related functions.
* @module Sharp
* @private

@@ -576,0 +579,0 @@ */

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

* Decorate the Sharp class with utility-related functions.
* @module Sharp
* @private

@@ -285,0 +286,0 @@ */

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

@@ -105,5 +105,5 @@ "homepage": "https://sharp.pixelplumbing.com",

"package-from-github-release": "node npm/from-github-release",
"docs-build": "node docs/build && node docs/search-index/build",
"docs-serve": "cd docs && npx serve",
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
"docs-build": "node docs/build.mjs",
"docs-serve": "cd docs && npm start",
"docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
},

@@ -143,47 +143,47 @@ "type": "commonjs",

"detect-libc": "^2.0.3",
"semver": "^7.6.3"
"semver": "^7.7.1"
},
"optionalDependencies": {
"@img/sharp-darwin-arm64": "0.33.5",
"@img/sharp-darwin-x64": "0.33.5",
"@img/sharp-libvips-darwin-arm64": "1.0.4",
"@img/sharp-libvips-darwin-x64": "1.0.4",
"@img/sharp-libvips-linux-arm": "1.0.5",
"@img/sharp-libvips-linux-arm64": "1.0.4",
"@img/sharp-libvips-linux-s390x": "1.0.4",
"@img/sharp-libvips-linux-x64": "1.0.4",
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4",
"@img/sharp-libvips-linuxmusl-x64": "1.0.4",
"@img/sharp-linux-arm": "0.33.5",
"@img/sharp-linux-arm64": "0.33.5",
"@img/sharp-linux-s390x": "0.33.5",
"@img/sharp-linux-x64": "0.33.5",
"@img/sharp-linuxmusl-arm64": "0.33.5",
"@img/sharp-linuxmusl-x64": "0.33.5",
"@img/sharp-wasm32": "0.33.5",
"@img/sharp-win32-ia32": "0.33.5",
"@img/sharp-win32-x64": "0.33.5"
"@img/sharp-darwin-arm64": "0.34.0-rc.0",
"@img/sharp-darwin-x64": "0.34.0-rc.0",
"@img/sharp-libvips-darwin-arm64": "1.1.0-rc4",
"@img/sharp-libvips-darwin-x64": "1.1.0-rc4",
"@img/sharp-libvips-linux-arm": "1.1.0-rc4.1",
"@img/sharp-libvips-linux-arm64": "1.1.0-rc4",
"@img/sharp-libvips-linux-ppc64": "1.1.0-rc4",
"@img/sharp-libvips-linux-s390x": "1.1.0-rc4",
"@img/sharp-libvips-linux-x64": "1.1.0-rc4",
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0-rc4",
"@img/sharp-libvips-linuxmusl-x64": "1.1.0-rc4",
"@img/sharp-linux-arm": "0.34.0-rc.0",
"@img/sharp-linux-arm64": "0.34.0-rc.0",
"@img/sharp-linux-s390x": "0.34.0-rc.0",
"@img/sharp-linux-x64": "0.34.0-rc.0",
"@img/sharp-linuxmusl-arm64": "0.34.0-rc.0",
"@img/sharp-linuxmusl-x64": "0.34.0-rc.0",
"@img/sharp-wasm32": "0.34.0-rc.0",
"@img/sharp-win32-ia32": "0.34.0-rc.0",
"@img/sharp-win32-x64": "0.34.0-rc.0"
},
"devDependencies": {
"@emnapi/runtime": "^1.2.0",
"@img/sharp-libvips-dev": "1.0.4",
"@img/sharp-libvips-dev-wasm32": "1.0.5",
"@img/sharp-libvips-win32-ia32": "1.0.4",
"@img/sharp-libvips-win32-x64": "1.0.4",
"@emnapi/runtime": "^1.3.1",
"@img/sharp-libvips-dev": "1.1.0-rc4",
"@img/sharp-libvips-dev-wasm32": "1.1.0-rc4",
"@img/sharp-libvips-win32-ia32": "1.1.0-rc4",
"@img/sharp-libvips-win32-x64": "1.1.0-rc4",
"@types/node": "*",
"async": "^3.2.5",
"cc": "^3.0.1",
"emnapi": "^1.2.0",
"exif-reader": "^2.0.1",
"emnapi": "^1.3.1",
"exif-reader": "^2.0.2",
"extract-zip": "^2.0.1",
"icc": "^3.0.0",
"jsdoc-to-markdown": "^8.0.3",
"jsdoc-to-markdown": "^9.1.1",
"license-checker": "^25.0.1",
"mocha": "^10.7.3",
"node-addon-api": "^8.1.0",
"nyc": "^17.0.0",
"mocha": "^11.1.0",
"node-addon-api": "^8.3.1",
"nyc": "^17.1.0",
"prebuild": "^13.0.1",
"semistandard": "^17.0.0",
"tar-fs": "^3.0.6",
"tsd": "^0.31.1"
"tar-fs": "^3.0.8",
"tsd": "^0.31.2"
},

@@ -195,3 +195,3 @@ "license": "Apache-2.0",

"config": {
"libvips": ">=8.15.3"
"libvips": ">=8.16.1"
},

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

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

}
// // PDF background color
if (HasAttr(input, "pdfBackground")) {
descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
}
// Create new image

@@ -160,8 +164,30 @@ if (HasAttr(input, "createChannels")) {

}
// Join images together
if (HasAttr(input, "joinAnimated")) {
descriptor->joinAnimated = AttrAsBool(input, "joinAnimated");
}
if (HasAttr(input, "joinAcross")) {
descriptor->joinAcross = AttrAsUint32(input, "joinAcross");
}
if (HasAttr(input, "joinShim")) {
descriptor->joinShim = AttrAsUint32(input, "joinShim");
}
if (HasAttr(input, "joinBackground")) {
descriptor->joinBackground = AttrAsVectorOfDouble(input, "joinBackground");
}
if (HasAttr(input, "joinHalign")) {
descriptor->joinHalign = AttrAsEnum<VipsAlign>(input, "joinHalign", VIPS_TYPE_ALIGN);
}
if (HasAttr(input, "joinValign")) {
descriptor->joinValign = AttrAsEnum<VipsAlign>(input, "joinValign", VIPS_TYPE_ALIGN);
}
// Limit input images to a given number of pixels, where pixels = width * height
descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
// Allow switch from random to sequential access
descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
if (HasAttr(input, "access")) {
descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
}
// Remove safety features and allow unlimited input
descriptor->unlimited = AttrAsBool(input, "unlimited");
// Use the EXIF orientation to auto orient the image
descriptor->autoOrient = AttrAsBool(input, "autoOrient");
return descriptor;

@@ -249,2 +275,3 @@ }

case ImageType::JXL: id = "jxl"; break;
case ImageType::RAD: id = "rad"; break;
case ImageType::VIPS: id = "vips"; break;

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

{ "VipsForeignLoadJxlBuffer", ImageType::JXL },
{ "VipsForeignLoadRadFile", ImageType::RAD },
{ "VipsForeignLoadRadBuffer", ImageType::RAD },
{ "VipsForeignLoadVips", ImageType::VIPS },

@@ -409,2 +438,5 @@ { "VipsForeignLoadVipsFile", ImageType::VIPS },

}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);

@@ -514,2 +546,5 @@ if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {

}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
image = VImage::new_from_file(descriptor->file.data(), option);

@@ -569,10 +604,2 @@ if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {

/*
Does this image have an alpha channel?
Uses colour space interpretation with number of channels to guess this.
*/
bool HasAlpha(VImage image) {
return image.has_alpha();
}
static void* RemoveExifCallback(VipsImage *image, char const *field, GValue *value, void *data) {

@@ -986,3 +1013,3 @@ std::vector<std::string> *fieldNames = static_cast<std::vector<std::string> *>(data);

// Add alpha channel to alphaColour colour
if (colour[3] < 255.0 || HasAlpha(image)) {
if (colour[3] < 255.0 || image.has_alpha()) {
alphaColour.push_back(colour[3] * multiplier);

@@ -993,3 +1020,3 @@ }

// Add non-transparent alpha channel, if required
if (colour[3] < 255.0 && !HasAlpha(image)) {
if (colour[3] < 255.0 && !image.has_alpha()) {
image = image.bandjoin(

@@ -1002,6 +1029,6 @@ VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));

/*
Removes alpha channel, if any.
Removes alpha channels, if any.
*/
VImage RemoveAlpha(VImage image) {
if (HasAlpha(image)) {
while (image.bands() > 1 && image.has_alpha()) {
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));

@@ -1016,3 +1043,3 @@ }

VImage EnsureAlpha(VImage image, double const value) {
if (!HasAlpha(image)) {
if (!image.has_alpha()) {
std::vector<double> alpha;

@@ -1019,0 +1046,0 @@ alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));

@@ -18,16 +18,12 @@ // Copyright 2013 Lovell Fuller and others.

#if (VIPS_MAJOR_VERSION < 8) || \
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 3)
#error "libvips version 8.15.3+ is required - please see https://sharp.pixelplumbing.com/install"
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 16) || \
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 16 && VIPS_MICRO_VERSION < 1)
#error "libvips version 8.16.1+ is required - please see https://sharp.pixelplumbing.com/install"
#endif
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#if defined(__has_include)
#if !__has_include(<filesystem>)
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
#endif
#if (defined(__clang__) && defined(__has_feature))
#if (!__has_feature(cxx_range_for))
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#endif
#endif

@@ -41,2 +37,3 @@ using vips::VImage;

std::string file;
bool autoOrient;
char *buffer;

@@ -79,4 +76,12 @@ VipsFailOn failOn;

int textAutofitDpi;
bool joinAnimated;
int joinAcross;
int joinShim;
std::vector<double> joinBackground;
VipsAlign joinHalign;
VipsAlign joinValign;
std::vector<double> pdfBackground;
InputDescriptor():
autoOrient(false),
buffer(nullptr),

@@ -86,3 +91,3 @@ failOn(VIPS_FAIL_ON_WARNING),

unlimited(false),
access(VIPS_ACCESS_RANDOM),
access(VIPS_ACCESS_SEQUENTIAL),
bufferLength(0),

@@ -115,3 +120,10 @@ isBuffer(false),

textWrap(VIPS_TEXT_WRAP_WORD),
textAutofitDpi(0) {}
textAutofitDpi(0),
joinAnimated(false),
joinAcross(1),
joinShim(0),
joinBackground{ 0.0, 0.0, 0.0, 255.0 },
joinHalign(VIPS_ALIGN_LOW),
joinValign(VIPS_ALIGN_LOW),
pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
};

@@ -155,2 +167,3 @@

JXL,
RAD,
VIPS,

@@ -242,8 +255,2 @@ RAW,

/*
Does this image have an alpha channel?
Uses colour space interpretation with number of channels to guess this.
*/
bool HasAlpha(VImage image);
/*
Remove all EXIF-related image fields.

@@ -378,3 +385,3 @@ */

/*
Removes alpha channel, if any.
Removes alpha channels, if any.
*/

@@ -381,0 +388,0 @@ VImage RemoveAlpha(VImage image);

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

#include <vector>
#include <cmath>

@@ -51,5 +52,8 @@ #include <napi.h>

}
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
baton->paletteBitDepth = image.get_int("palette-bit-depth");
if (image.get_typeof(VIPS_META_PALETTE) == G_TYPE_INT) {
baton->isPalette = image.get_int(VIPS_META_PALETTE);
}
if (image.get_typeof(VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT) {
baton->bitsPerSample = image.get_int(VIPS_META_BITS_PER_SAMPLE);
}
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {

@@ -96,3 +100,3 @@ baton->pages = image.get_int(VIPS_META_N_PAGES);

// Derived attributes
baton->hasAlpha = sharp::HasAlpha(image);
baton->hasAlpha = image.has_alpha();
baton->orientation = sharp::ExifOrientation(image);

@@ -177,4 +181,9 @@ // EXIF

info.Set("isProgressive", baton->isProgressive);
if (baton->paletteBitDepth > 0) {
info.Set("paletteBitDepth", baton->paletteBitDepth);
info.Set("isPalette", baton->isPalette);
if (baton->bitsPerSample > 0) {
info.Set("bitsPerSample", baton->bitsPerSample);
if (baton->isPalette) {
// Deprecated, remove with libvips 8.17.0
info.Set("paletteBitDepth", baton->bitsPerSample);
}
}

@@ -225,11 +234,11 @@ if (baton->pages > 0) {

if (!baton->background.empty()) {
Napi::Object background = Napi::Object::New(env);
if (baton->background.size() == 3) {
Napi::Object background = Napi::Object::New(env);
background.Set("r", baton->background[0]);
background.Set("g", baton->background[1]);
background.Set("b", baton->background[2]);
info.Set("background", background);
} else {
info.Set("background", baton->background[0]);
background.Set("gray", round(baton->background[0] * 100 / 255));
}
info.Set("background", background);
}

@@ -241,2 +250,11 @@ info.Set("hasProfile", baton->hasProfile);

}
Napi::Object autoOrient = Napi::Object::New(env);
info.Set("autoOrient", autoOrient);
if (baton->orientation >= 5) {
autoOrient.Set("width", baton->height);
autoOrient.Set("height", baton->width);
} else {
autoOrient.Set("width", baton->width);
autoOrient.Set("height", baton->height);
}
if (baton->exifLength > 0) {

@@ -243,0 +261,0 @@ info.Set("exif", Napi::Buffer<char>::NewOrCopy(env, baton->exif, baton->exifLength, sharp::FreeCallback));

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

bool isProgressive;
int paletteBitDepth;
bool isPalette;
int bitsPerSample;
int pages;

@@ -63,3 +64,4 @@ int pageHeight;

isProgressive(false),
paletteBitDepth(0),
isPalette(false),
bitsPerSample(0),
pages(0),

@@ -66,0 +68,0 @@ pageHeight(0),

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

// Apply lookup table
if (HasAlpha(image)) {
if (image.has_alpha()) {
VImage alpha = image[image.bands() - 1];

@@ -87,3 +87,3 @@ image = RemoveAlpha(image)

// Attach original alpha channel, if any
if (HasAlpha(image)) {
if (image.has_alpha()) {
// Extract original alpha channel

@@ -111,3 +111,3 @@ VImage alpha = image[image.bands() - 1];

VImage Gamma(VImage image, double const exponent) {
if (HasAlpha(image)) {
if (image.has_alpha()) {
// Separate alpha channel

@@ -138,3 +138,3 @@ VImage alpha = image[image.bands() - 1];

VImage Negate(VImage image, bool const negateAlpha) {
if (HasAlpha(image) && !negateAlpha) {
if (image.has_alpha() && !negateAlpha) {
// Separate alpha channel

@@ -212,3 +212,3 @@ VImage alpha = image[image.bands() - 1];

VipsInterpretation colourspaceBeforeModulate = image.interpretation();
if (HasAlpha(image)) {
if (image.has_alpha()) {
// Separate alpha channel

@@ -305,3 +305,3 @@ VImage alpha = image[image.bands() - 1];

std::vector<double> backgroundAlpha({ background.back() });
if (HasAlpha(image)) {
if (image.has_alpha()) {
background.pop_back();

@@ -316,3 +316,3 @@ } else {

->set("threshold", threshold));
if (HasAlpha(image)) {
if (image.has_alpha()) {
// Search alpha channel (A)

@@ -354,3 +354,3 @@ int leftA, topA, widthA, heightA;

bool const uchar = !Is16Bit(image.interpretation());
if (HasAlpha(image) && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
if (image.has_alpha() && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
// Separate alpha channel

@@ -368,3 +368,3 @@ VImage alpha = image[bands - 1];

VImage Unflatten(VImage image) {
if (HasAlpha(image)) {
if (image.has_alpha()) {
VImage alpha = image[image.bands() - 1];

@@ -371,0 +371,0 @@ VImage noAlpha = RemoveAlpha(image);

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

sharp::InputDescriptor *input;
std::vector<sharp::InputDescriptor *> join;
std::string formatOut;

@@ -113,3 +114,2 @@ std::string fileOut;

int claheMaxSlope;
bool useExifOrientation;
int angle;

@@ -162,2 +162,3 @@ double rotationAngle;

bool webpSmartSubsample;
bool webpSmartDeblock;
VipsForeignWebpPreset webpPreset;

@@ -287,3 +288,2 @@ int webpEffort;

claheMaxSlope(3),
useExifOrientation(false),
angle(0),

@@ -335,2 +335,3 @@ rotationAngle(0.0),

webpSmartSubsample(false),
webpSmartDeblock(false),
webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),

@@ -337,0 +338,0 @@ webpEffort(4),

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

// Image is not opaque when alpha layer is present and contains a non-mamixa value
if (sharp::HasAlpha(image)) {
if (image.has_alpha()) {
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());

@@ -64,0 +64,0 @@ if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {

@@ -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"
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad"
}) {

@@ -237,6 +237,6 @@ // Input

// Premultiply and remove alpha
if (sharp::HasAlpha(image1)) {
if (image1.has_alpha()) {
image1 = image1.premultiply().extract_band(1, VImage::option()->set("n", image1.bands() - 1));
}
if (sharp::HasAlpha(image2)) {
if (image2.has_alpha()) {
image2 = image2.premultiply().extract_band(1, VImage::option()->set("n", image2.bands() - 1));

@@ -243,0 +243,0 @@ }

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

Sorry, the diff of this file is not supported yet

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