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.28.3 to 0.29.0

lib/sharp.js

12

install/dll-copy.js

@@ -7,15 +7,15 @@ 'use strict';

const libvips = require('../lib/libvips');
const platform = require('../lib/platform');
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
const platform = process.env.npm_config_platform || process.platform;
if (platform === 'win32') {
const buildDir = path.join(__dirname, '..', 'build');
const buildReleaseDir = path.join(buildDir, 'Release');
const platformAndArch = platform();
if (platformAndArch.startsWith('win32')) {
const buildReleaseDir = path.join(__dirname, '..', 'build', 'Release');
libvips.log(`Creating ${buildReleaseDir}`);
try {
libvips.mkdirSync(buildDir);
libvips.mkdirSync(buildReleaseDir);
} catch (err) {}
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, 'lib');
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch, 'lib');
libvips.log(`Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);

@@ -22,0 +22,0 @@ try {

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

'darwin-x64',
'darwin-arm64',
'linux-arm64',

@@ -39,3 +40,2 @@ 'linux-x64',

const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
const supportsBrotli = ('BrotliDecompress' in zlib);
const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE);

@@ -61,5 +61,3 @@

const extractTarball = function (tarPath, platformAndArch) {
const vendorPath = path.join(__dirname, '..', 'vendor');
libvips.mkdirSync(vendorPath);
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
const versionedVendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch);
libvips.mkdirSync(versionedVendorPath);

@@ -74,3 +72,3 @@

fs.createReadStream(tarPath),
supportsBrotli ? new zlib.BrotliDecompress() : new zlib.Gunzip(),
new zlib.BrotliDecompress(),
tarFs.extract(versionedVendorPath, { ignore }),

@@ -128,6 +126,4 @@ function (err) {

const extension = supportsBrotli ? 'br' : 'gz';
// Download to per-process temporary file
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.' + extension;
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.br';
const tarPathCache = path.join(libvips.cachePath(), tarFilename);

@@ -134,0 +130,0 @@ if (fs.existsSync(tarPathCache)) {

@@ -75,10 +75,14 @@ 'use strict';

* @example
* sharp(input)
* // green.jpg is a greyscale image containing the green channel of the input
* await sharp(input)
* .extractChannel('green')
* .toColourspace('b-w')
* .toFile('green.jpg', function(err, info) {
* // info.channels === 1
* // green.jpg is a greyscale image containing the green channel of the input
* });
* .toFile('green.jpg');
*
* @example
* // red1 is the red value of the first pixel, red2 the second pixel etc.
* const [red1, red2, ...] = await sharp(input)
* .extractChannel(0)
* .raw()
* .toBuffer();
*
* @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.

@@ -98,3 +102,3 @@ * @returns {Sharp}

}
return this;
return this.toColourspace('b-w');
}

@@ -101,0 +105,0 @@

@@ -58,2 +58,41 @@ 'use strict';

/**
* Set the pipeline colourspace.
*
* The input image will be converted to the provided colourspace at the start of the pipeline.
* All operations will use this colourspace before converting to the output colourspace, as defined by {@link toColourspace}.
*
* This feature is experimental and has not yet been fully-tested with all operations.
*
* @since 0.29.0
*
* @example
* // Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
* await sharp(input)
* .pipelineColourspace('rgb16')
* .toColourspace('srgb')
* .toFile('16bpc-pipeline-to-8bpc-output.png')
*
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774)
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function pipelineColourspace (colourspace) {
if (!is.string(colourspace)) {
throw is.invalidParameterError('colourspace', 'string', colourspace);
}
this.options.colourspaceInput = colourspace;
return this;
}
/**
* Alternative spelling of `pipelineColourspace`.
* @param {string} [colorspace] - pipeline colorspace.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function pipelineColorspace (colorspace) {
return this.pipelineColourspace(colorspace);
}
/**
* Set the output colourspace.

@@ -68,3 +107,3 @@ * By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.

*
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568)
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794)
* @returns {Sharp}

@@ -124,2 +163,4 @@ * @throws {Error} Invalid parameters

grayscale,
pipelineColourspace,
pipelineColorspace,
toColourspace,

@@ -126,0 +167,0 @@ toColorspace,

@@ -8,29 +8,4 @@ 'use strict';

require('./libvips').hasVendoredLibvips();
require('./sharp');
/* istanbul ignore next */
try {
require('../build/Release/sharp.node');
} catch (err) {
// Bail early if bindings aren't available
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, ''];
if (/NODE_MODULE_VERSION/.test(err.message)) {
help.push('- Ensure the version of Node.js used at install time matches that used at runtime');
} else if (/invalid ELF header/.test(err.message)) {
help.push(`- Ensure "${process.platform}" is used at install time as well as runtime`);
} else if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
help.push('- Run "brew update && brew upgrade vips"');
} else {
help.push(
'- Remove the "node_modules/sharp" directory then run',
' "npm install --ignore-scripts=false --verbose sharp" and look for errors'
);
}
help.push(
'- Consult the installation documentation at https://sharp.pixelplumbing.com/install',
'- Search for this error at https://github.com/lovell/sharp/issues', ''
);
const error = help.join('\n');
throw new Error(error);
}
// Use NODE_DEBUG=sharp to enable libvips warnings

@@ -121,4 +96,5 @@ const debuglog = util.debuglog('sharp');

*
* @param {(Buffer|Uint8Array|Uint8ClampedArray|string)} [input] - if present, can be
* a Buffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data, or
* @param {(Buffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
* a Buffer / 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.

@@ -209,2 +185,3 @@ * JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.

negate: false,
negateAlpha: true,
medianSize: 0,

@@ -235,2 +212,3 @@ blurSigma: 0,

colourspace: 'srgb',
colourspaceInput: 'last',
composite: [],

@@ -283,3 +261,4 @@ // output

heifSpeed: 5,
heifChromaSubsampling: '4:2:0',
heifChromaSubsampling: '4:4:4',
rawDepth: 'uchar',
tileSize: 256,

@@ -286,0 +265,0 @@ tileOverlap: 0,

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

const is = require('./is');
const sharp = require('../build/Release/sharp.node');
const sharp = require('./sharp');

@@ -38,4 +38,3 @@ /**

inputDescriptor.buffer = input;
} else if (is.uint8Array(input)) {
// Uint8Array or Uint8ClampedArray
} else if (is.typedArray(input)) {
if (input.length === 0) {

@@ -109,2 +108,33 @@ throw Error('Input Bit Array is empty');

inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
switch (input.constructor) {
case Uint8Array:
case Uint8ClampedArray:
inputDescriptor.rawDepth = 'uchar';
break;
case Int8Array:
inputDescriptor.rawDepth = 'char';
break;
case Uint16Array:
inputDescriptor.rawDepth = 'ushort';
break;
case Int16Array:
inputDescriptor.rawDepth = 'short';
break;
case Uint32Array:
inputDescriptor.rawDepth = 'uint';
break;
case Int32Array:
inputDescriptor.rawDepth = 'int';
break;
case Float32Array:
inputDescriptor.rawDepth = 'float';
break;
case Float64Array:
inputDescriptor.rawDepth = 'double';
break;
default:
inputDescriptor.rawDepth = 'uchar';
break;
}
} else {

@@ -277,2 +307,4 @@ throw new Error('Expected width, height and channels for raw pixel input');

* - `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
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile

@@ -363,2 +395,5 @@ * - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel

*
* **Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
* written to a buffer in order to run `stats` on the result (see third example).
*
* @example

@@ -376,2 +411,9 @@ * const image = sharp(inputJpg);

*
* @example
* const image = sharp(input);
* // store intermediate result
* const part = await image.extract(region).toBuffer();
* // create new instance to obtain statistics of extracted region
* const stats = await sharp(part).stats();
*
* @param {Function} [callback] - called with the arguments `(err, stats)`

@@ -378,0 +420,0 @@ * @returns {Promise<Object>}

@@ -52,8 +52,22 @@ 'use strict';

/**
* Is this value a Uint8Array or Uint8ClampedArray object?
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
* @private
*/
const uint8Array = function (val) {
// allow both since Uint8ClampedArray simply clamps the values between 0-255
return val instanceof Uint8Array || val instanceof Uint8ClampedArray;
const typedArray = function (val) {
if (defined(val)) {
switch (val.constructor) {
case Uint8Array:
case Uint8ClampedArray:
case Int8Array:
case Uint16Array:
case Int16Array:
case Uint32Array:
case Int32Array:
case Float32Array:
case Float64Array:
return true;
}
}
return false;
};

@@ -123,3 +137,3 @@

buffer: buffer,
uint8Array: uint8Array,
typedArray: typedArray,
string: string,

@@ -126,0 +140,0 @@ number: number,

@@ -24,5 +24,5 @@ 'use strict';

try {
fs.mkdirSync(dirPath);
fs.mkdirSync(dirPath, { recursive: true });
} catch (err) {
/* istanbul ignore if */
/* istanbul ignore next */
if (err.code !== 'EEXIST') {

@@ -71,19 +71,4 @@ throw err;

const hasVendoredLibvips = function () {
const currentPlatformId = platform();
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion);
let vendorPlatformId;
try {
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
} catch (err) {}
/* istanbul ignore else */
if (vendorPlatformId) {
/* istanbul ignore else */
if (currentPlatformId === vendorPlatformId) {
return true;
} else {
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.`);
}
} else {
return false;
}
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platform());
return fs.existsSync(vendorPath);
};

@@ -90,0 +75,0 @@

@@ -328,7 +328,15 @@ 'use strict';

* Produce the "negative" of the image.
* @param {Boolean} [negate=true]
* @param {Object} [options]
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
* @returns {Sharp}
*/
function negate (negate) {
this.options.negate = is.bool(negate) ? negate : true;
function negate (options) {
this.options.negate = is.bool(options) ? options : true;
if (is.plainObject(options) && 'alpha' in options) {
if (!is.bool(options.alpha)) {
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
} else {
this.options.negateAlpha = options.alpha;
}
}
return this;

@@ -335,0 +343,0 @@ }

'use strict';
const is = require('./is');
const sharp = require('../build/Release/sharp.node');
const sharp = require('./sharp');

@@ -663,3 +663,3 @@ const formats = new Map([

* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest)
* @param {string} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling, requires libvips v8.11.0
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
* @returns {Sharp}

@@ -685,3 +685,3 @@ * @throws {Error} Invalid options

* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest)
* @param {string} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling, requires libvips v8.11.0
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
* @returns {Sharp}

@@ -732,3 +732,3 @@ * @throws {Error} Invalid options

/**
* Force output to be raw, uncompressed, 8-bit unsigned integer (unit8) pixel data.
* Force output to be raw, uncompressed pixel data.
* Pixel ordering is left-to-right, top-to-bottom, without padding.

@@ -738,3 +738,3 @@ * Channel ordering will be RGB or RGBA for non-greyscale colourspaces.

* @example
* // Extract raw RGB pixel data from JPEG input
* // Extract raw, unsigned 8-bit RGB pixel data from JPEG input
* const { data, info } = await sharp('input.jpg')

@@ -745,3 +745,3 @@ * .raw()

* @example
* // Extract alpha channel as raw pixel data from PNG input
* // Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
* const data = await sharp('input.png')

@@ -751,8 +751,21 @@ * .ensureAlpha()

* .toColourspace('b-w')
* .raw()
* .raw({ depth: 'ushort' })
* .toBuffer();
*
* @returns {Sharp}
* @param {Object} [options] - output options
* @param {string} [options.depth='uchar'] - bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex
* @throws {Error} Invalid options
*/
function raw () {
function raw (options) {
if (is.object(options)) {
if (is.defined(options.depth)) {
if (is.string(options.depth) && is.inArray(options.depth,
['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'float', 'complex', 'double', 'dpcomplex']
)) {
this.options.rawDepth = options.depth;
} else {
throw is.invalidParameterError('depth', 'one of: char, uchar, short, ushort, int, uint, float, complex, double, dpcomplex', options.depth);
}
}
}
return this._updateFormatOut('raw');

@@ -759,0 +772,0 @@ }

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

const is = require('./is');
const sharp = require('../build/Release/sharp.node');
const sharp = require('./sharp');

@@ -10,0 +10,0 @@ /**

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

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

"Michael Nutt <michael@nutt.im>",
"Brad Parham <baparham@gmail.com>"
"Brad Parham <baparham@gmail.com>",
"Taneli Vatanen <taneli.vatanen@gmail.com>"
],

@@ -125,6 +126,6 @@ "scripts": {

"dependencies": {
"color": "^3.1.3",
"color": "^4.0.1",
"detect-libc": "^1.0.3",
"node-addon-api": "^3.2.0",
"prebuild-install": "^6.1.2",
"node-addon-api": "^4.0.0",
"prebuild-install": "^6.1.4",
"semver": "^7.3.5",

@@ -136,3 +137,3 @@ "simple-get": "^3.1.0",

"devDependencies": {
"async": "^3.2.0",
"async": "^3.2.1",
"cc": "^3.0.1",

@@ -144,17 +145,17 @@ "decompress-zip": "^0.3.3",

"license-checker": "^25.0.1",
"mocha": "^8.4.0",
"mock-fs": "^4.14.0",
"mocha": "^9.0.3",
"mock-fs": "^5.0.0",
"nyc": "^15.1.0",
"prebuild": "^10.0.1",
"rimraf": "^3.0.2",
"semistandard": "^16.0.0"
"semistandard": "^16.0.1"
},
"license": "Apache-2.0",
"config": {
"libvips": "8.10.6",
"libvips": "8.11.3",
"runtime": "napi",
"target": 3
"target": 5
},
"engines": {
"node": ">=10"
"node": ">=12.13.0"
},

@@ -166,3 +167,3 @@ "funding": {

"napi_versions": [
3
5
]

@@ -169,0 +170,0 @@ },

@@ -19,3 +19,3 @@ # sharp

Most modern macOS, Windows and Linux systems running Node.js v10+
Most modern macOS, Windows and Linux systems running Node.js >= 12.13.0
do not require any additional install or runtime dependencies.

@@ -103,3 +103,3 @@

[![Test Coverage](https://coveralls.io/repos/lovell/sharp/badge.svg?branch=master)](https://coveralls.io/r/lovell/sharp?branch=master)
[![N-API v3](https://img.shields.io/badge/N--API-v3-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix)
[![Node-API v5](https://img.shields.io/badge/Node--API-v5-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix)

@@ -106,0 +106,0 @@ ## Licensing

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