Socket
Socket
Sign inDemoInstall

sharp

Package Overview
Dependencies
Maintainers
1
Versions
156
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.23.4 to 0.24.0

src/libvips/cplusplus/VConnection.cpp

11

install/libvips.js

@@ -26,3 +26,3 @@ 'use strict';

npmLog.info('sharp', 'Attempting to build from source via node-gyp but this may fail due to the above error');
npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/page/install for required dependencies');
npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/install for required dependencies');
process.exit(1);

@@ -70,4 +70,7 @@ };

}
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.17.0')) {
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version) {
const minimumGlibcVersion = arch === 'arm64' ? '2.29.0' : '2.17.0';
if (semver.lt(`${detectLibc.version}.0`, minimumGlibcVersion)) {
throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
}
}

@@ -89,3 +92,3 @@ // Download to per-process temporary file

} else if (response.statusCode === 404) {
fail(new Error(`Prebuilt libvips binaries are not yet available for ${platformAndArch}`));
fail(new Error(`Prebuilt libvips ${minimumLibvipsVersion} binaries are not yet available for ${platformAndArch}`));
} else if (response.statusCode !== 200) {

@@ -92,0 +95,0 @@ fail(new Error(`Status ${response.statusCode} ${response.statusMessage}`));

@@ -35,2 +35,4 @@ 'use strict';

*
* @since 0.21.2
*
* @example

@@ -37,0 +39,0 @@ * sharp('rgb.jpg')

@@ -56,2 +56,4 @@ 'use strict';

*
* @since 0.22.0
*
* @example

@@ -58,0 +60,0 @@ * sharp('input.png')

@@ -5,3 +5,2 @@ 'use strict';

const stream = require('stream');
const events = require('events');
const is = require('./is');

@@ -11,6 +10,5 @@

let sharp;
/* istanbul ignore next */
try {
sharp = require('../build/Release/sharp.node');
require('../build/Release/sharp.node');
} catch (err) {

@@ -23,11 +21,16 @@ // Bail early if bindings aren't available

help.push(`- Ensure "${process.platform}" is used at install time as well as runtime`);
} else if (/Cannot find module/.test(err.message)) {
help.push('- Run "npm rebuild --verbose sharp" and look for errors');
} else {
help.push('- Remove the "node_modules/sharp" directory, run "npm install" and look for errors');
help.push(
'- Remove the "node_modules/sharp" directory then run',
' "npm install --ignore-scripts=false --verbose" and look for errors'
);
}
help.push(
'- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/',
'- Consult the installation documentation at https://sharp.pixelplumbing.com/install',
'- Search for this error at https://github.com/lovell/sharp/issues', ''
);
console.error(help.join('\n'));
process.exit(1);
const error = help.join('\n');
throw new Error(error);
}

@@ -39,3 +42,3 @@

/**
* @class Sharp
* @constructs sharp
*

@@ -90,2 +93,7 @@ * Constructor factory to create an instance of `sharp`, to which further methods are chained.

* Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid.
* @param {Number|Boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
* @param {Boolean} [options.sequentialRead=false] - Set this to `true` to use sequential rather than random access where possible.
* This can reduce memory usage and might improve performance on some systems.
* @param {Number} [options.density=72] - number representing the DPI for vector images.

@@ -115,5 +123,2 @@ * @param {Number} [options.pages=1] - number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages.

this.options = {
// input options
sequentialRead: false,
limitInputPixels: Math.pow(0x3FFF, 2),
// resize options

@@ -229,3 +234,3 @@ topOffsetPre: -1,

queueListener: function (queueLength) {
queue.emit('change', queueLength);
Sharp.queue.emit('change', queueLength);
}

@@ -239,36 +244,34 @@ };

/**
* An EventEmitter that emits a `change` event when a task is either:
* - queued, waiting for _libuv_ to provide a worker thread
* - complete
* @member
* Take a "snapshot" of the Sharp instance, returning a new instance.
* Cloned instances inherit the input of their parent instance.
* This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
*
* @example
* sharp.queue.on('change', function(queueLength) {
* console.log('Queue contains ' + queueLength + ' task(s)');
* });
* const pipeline = sharp().rotate();
* pipeline.clone().resize(800, 600).pipe(firstWritableStream);
* pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
* readableStream.pipe(pipeline);
* // firstWritableStream receives auto-rotated, resized readableStream
* // secondWritableStream receives auto-rotated, extracted region of readableStream
*
* @returns {Sharp}
*/
const queue = new events.EventEmitter();
Sharp.queue = queue;
function clone () {
// Clone existing options
const clone = this.constructor.call();
clone.options = Object.assign({}, this.options);
// Pass 'finish' event to clone for Stream-based input
if (this._isStreamInput()) {
this.on('finish', () => {
// Clone inherits input data
this._flattenBufferIn();
clone.options.bufferIn = this.options.bufferIn;
clone.emit('finish');
});
}
return clone;
}
Object.assign(Sharp.prototype, { clone });
/**
* An Object containing nested boolean values representing the available input and output formats/methods.
* @example
* console.log(sharp.format);
* @returns {Object}
*/
Sharp.format = sharp.format();
/**
* An Object containing the version numbers of libvips and its dependencies.
* @member
* @example
* console.log(sharp.versions);
*/
Sharp.versions = {
vips: sharp.libvipsVersion()
};
try {
Sharp.versions = require('../vendor/versions.json');
} catch (err) {}
/**
* Export constructor.

@@ -275,0 +278,0 @@ * @private

'use strict';
const util = require('util');
const color = require('color');

@@ -12,3 +13,7 @@ const is = require('./is');

function _createInputDescriptor (input, inputOptions, containerOptions) {
const inputDescriptor = { failOnError: true };
const inputDescriptor = {
failOnError: true,
limitInputPixels: Math.pow(0x3FFF, 2),
sequentialRead: false
};
if (is.string(input)) {

@@ -27,7 +32,9 @@ // filesystem

}
} else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
// Stream
inputDescriptor.buffer = [];
} else {
throw new Error('Unsupported input ' + typeof input);
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''
}`);
}

@@ -51,2 +58,22 @@ if (is.object(inputOptions)) {

}
// limitInputPixels
if (is.defined(inputOptions.limitInputPixels)) {
if (is.bool(inputOptions.limitInputPixels)) {
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels
? Math.pow(0x3FFF, 2)
: 0;
} else if (is.integer(inputOptions.limitInputPixels) && inputOptions.limitInputPixels >= 0) {
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels;
} else {
throw is.invalidParameterError('limitInputPixels', 'integer >= 0', inputOptions.limitInputPixels);
}
}
// sequentialRead
if (is.defined(inputOptions.sequentialRead)) {
if (is.bool(inputOptions.sequentialRead)) {
inputDescriptor.sequentialRead = inputOptions.sequentialRead;
} else {
throw is.invalidParameterError('sequentialRead', 'boolean', inputOptions.sequentialRead);
}
}
// Raw pixel input

@@ -159,33 +186,2 @@ if (is.defined(inputOptions.raw)) {

/**
* Take a "snapshot" of the Sharp instance, returning a new instance.
* Cloned instances inherit the input of their parent instance.
* This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
*
* @example
* const pipeline = sharp().rotate();
* pipeline.clone().resize(800, 600).pipe(firstWritableStream);
* pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
* readableStream.pipe(pipeline);
* // firstWritableStream receives auto-rotated, resized readableStream
* // secondWritableStream receives auto-rotated, extracted region of readableStream
*
* @returns {Sharp}
*/
function clone () {
// Clone existing options
const clone = this.constructor.call();
clone.options = Object.assign({}, this.options);
// Pass 'finish' event to clone for Stream-based input
if (this._isStreamInput()) {
this.on('finish', () => {
// Clone inherits input data
this._flattenBufferIn();
clone.options.bufferIn = this.options.bufferIn;
clone.emit('finish');
});
}
return clone;
}
/**
* Fast access to (uncached) image metadata without decoding any compressed image data.

@@ -205,3 +201,5 @@ * A `Promise` is returned when `callback` is not provided.

* - `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 this PDF image will be.
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
* - `pagePrimary`: Number of the primary page in a HEIF image

@@ -342,10 +340,5 @@ * - `hasProfile`: Boolean indicating the presence of an embedded ICC profile

/**
* Do not process input images where the number of pixels (width x height) exceeds this limit.
* Assumes image dimensions contained in the input metadata can be trusted.
* The default limit is 268402689 (0x3FFF x 0x3FFF) pixels.
* @param {(Number|Boolean)} limit - an integral Number of pixels, zero or false to remove limit, true to use default limit.
* @returns {Sharp}
* @throws {Error} Invalid limit
*/
function limitInputPixels (limit) {
* @private
*/
const limitInputPixels = util.deprecate(function limitInputPixels (limit) {
// if we pass in false we represent the integer as 0 to disable

@@ -358,3 +351,3 @@ if (limit === false) {

if (is.integer(limit) && limit >= 0) {
this.options.limitInputPixels = limit;
this.options.input.limitInputPixels = limit;
} else {

@@ -364,17 +357,11 @@ throw is.invalidParameterError('limitInputPixels', 'integer', limit);

return this;
}
}, 'limitInputPixels is deprecated, use sharp(input, { limitInputPixels: false }) instead');
/**
* An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
* This will reduce memory usage and can improve performance on some systems.
*
* The default behaviour *before* function call is `false`, meaning the libvips access method is not sequential.
*
* @param {Boolean} [sequentialRead=true]
* @returns {Sharp}
* @private
*/
function sequentialRead (sequentialRead) {
this.options.sequentialRead = is.bool(sequentialRead) ? sequentialRead : true;
const sequentialRead = util.deprecate(function sequentialRead (sequentialRead) {
this.options.input.sequentialRead = is.bool(sequentialRead) ? sequentialRead : true;
return this;
}
}, 'sequentialRead is deprecated, use sharp(input, { sequentialRead: true }) instead');

@@ -393,5 +380,5 @@ /**

// Public
clone,
metadata,
stats,
// Deprecated
limitInputPixels,

@@ -398,0 +385,0 @@ sequentialRead

@@ -382,2 +382,4 @@ 'use strict';

*
* @since 0.21.1
*
* @example

@@ -420,2 +422,4 @@ * sharp(input)

*
* @since 0.22.1
*
* @example

@@ -422,0 +426,0 @@ * sharp(input)

@@ -6,2 +6,13 @@ 'use strict';

const formats = new Map([
['heic', 'heif'],
['heif', 'heif'],
['jpeg', 'jpeg'],
['jpg', 'jpeg'],
['png', 'png'],
['raw', 'raw'],
['tiff', 'tiff'],
['webp', 'webp']
]);
/**

@@ -140,2 +151,24 @@ * Write output image data to a file.

/**
* Force output to a given format.
*
* @example
* // Convert any input to PNG output
* const data = await sharp(input)
* .toFormat('png')
* .toBuffer();
*
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
* @param {Object} options - output options
* @returns {Sharp}
* @throws {Error} unsupported format or options
*/
function toFormat (format, options) {
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
if (!actualFormat) {
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
}
return this[actualFormat](options);
}
/**
* Use these JPEG options for output image.

@@ -449,2 +482,4 @@ *

*
* @since 0.23.0
*
* @param {Object} [options] - output options

@@ -502,36 +537,3 @@ * @param {Number} [options.quality=80] - quality, integer 1-100

const formats = new Map([
['heic', 'heif'],
['heif', 'heif'],
['jpeg', 'jpeg'],
['jpg', 'jpeg'],
['png', 'png'],
['raw', 'raw'],
['tiff', 'tiff'],
['webp', 'webp']
]);
/**
* Force output to a given format.
*
* @example
* // Convert any input to PNG output
* const data = await sharp(input)
* .toFormat('png')
* .toBuffer();
*
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
* @param {Object} options - output options
* @returns {Sharp}
* @throws {Error} unsupported format or options
*/
function toFormat (format, options) {
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
if (!actualFormat) {
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
}
return this[actualFormat](options);
}
/**
* Use tile-based deep zoom (image pyramid) output.

@@ -784,2 +786,3 @@ * Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.

withMetadata,
toFormat,
jpeg,

@@ -791,3 +794,2 @@ png,

raw,
toFormat,
tile,

@@ -794,0 +796,0 @@ // Private

@@ -176,2 +176,10 @@ 'use strict';

*
* @example
* const scaleByHalf = await sharp(input)
* .metadata()
* .then(({ width }) => sharp(input)
* .resize(Math.round(width * 0.5))
* .toBuffer()
* );
*
* @param {Number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.

@@ -178,0 +186,0 @@ * @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.

'use strict';
const events = require('events');
const is = require('./is');

@@ -7,2 +8,24 @@ const sharp = require('../build/Release/sharp.node');

/**
* An Object containing nested boolean values representing the available input and output formats/methods.
* @member
* @example
* console.log(sharp.format);
* @returns {Object}
*/
const format = sharp.format();
/**
* An Object containing the version numbers of libvips and its dependencies.
* @member
* @example
* console.log(sharp.versions);
*/
let versions = {
vips: sharp.libvipsVersion()
};
try {
versions = require('../vendor/versions.json');
} catch (err) {}
/**
* Gets or, when options are provided, sets the limits of _libvips'_ operation cache.

@@ -66,2 +89,14 @@ * Existing entries in the cache will be trimmed after any change in limits.

/**
* An EventEmitter that emits a `change` event when a task is either:
* - queued, waiting for _libuv_ to provide a worker thread
* - complete
* @member
* @example
* sharp.queue.on('change', function(queueLength) {
* console.log('Queue contains ' + queueLength + ' task(s)');
* });
*/
const queue = new events.EventEmitter();
/**
* Provides access to internal task counters.

@@ -115,2 +150,5 @@ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.

});
Sharp.format = format;
Sharp.versions = versions;
Sharp.queue = queue;
};
{
"name": "sharp",
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
"version": "0.23.4",
"version": "0.24.0",
"author": "Lovell Fuller <npm@lovell.info>",

@@ -67,3 +67,4 @@ "homepage": "https://github.com/lovell/sharp",

"Paul Neave <paul.neave@gmail.com>",
"Brendan Kennedy <brenwken@gmail.com>"
"Brendan Kennedy <brenwken@gmail.com>",
"Brychan Bennett-Odlum <git@brychan.io>"
],

@@ -78,3 +79,5 @@ "scripts": {

"test-leak": "./test/leak/leak.sh",
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done"
"docs-build": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done",
"docs-serve": "cd docs && npx serve",
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
},

@@ -84,4 +87,2 @@ "main": "lib/index.js",

"binding.gyp",
"docs/**",
"!docs/css/**",
"install/**",

@@ -117,3 +118,3 @@ "lib/**",

"prebuild-install": "^5.3.3",
"semver": "^6.3.0",
"semver": "^7.1.1",
"simple-get": "^3.1.0",

@@ -131,6 +132,6 @@ "tar": "^5.0.5",

"license-checker": "^25.0.1",
"mocha": "^6.2.2",
"mocha": "^7.0.0",
"mock-fs": "^4.10.4",
"nyc": "^14.1.1",
"prebuild": "^9.1.1",
"nyc": "^15.0.0",
"prebuild": "^10.0.0",
"prebuild-ci": "^3.1.0",

@@ -142,6 +143,6 @@ "rimraf": "^3.0.0",

"config": {
"libvips": "8.8.1"
"libvips": "8.9.0"
},
"engines": {
"node": ">=8.5.0"
"node": ">=10.13.0"
},

@@ -148,0 +149,0 @@ "funding": {

@@ -23,4 +23,4 @@ # sharp

Most modern 64-bit OS X, Windows and Linux systems running
Node versions 8, 10, 12 and 13
Most modern 64-bit macOS, Windows and Linux systems running
Node versions 10, 12 and 13
do not require any additional install or runtime dependencies.

@@ -106,3 +106,3 @@

Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 Lovell Fuller and contributors.
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Lovell Fuller and contributors.

@@ -109,0 +109,0 @@ Licensed under the Apache License, Version 2.0 (the "License");

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc