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.33.0-alpha.11 to 0.33.0-rc.2

10

lib/colour.js

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

/**
* Tint the image using the provided chroma while preserving the image luminance.
* Tint the image using the provided colour.
* An alpha channel may be present and will be unchanged by the operation.

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

*
* @param {string|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
* @param {string|Object} tint - Parsed by the [color](https://www.npmjs.org/package/color) module.
* @returns {Sharp}
* @throws {Error} Invalid parameter
*/
function tint (rgb) {
const colour = color(rgb);
this.options.tintA = colour.a();
this.options.tintB = colour.b();
function tint (tint) {
this._setBackgroundColourOption('tint', tint);
return this;

@@ -41,0 +39,0 @@ }

10

lib/constructor.js

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

// operations
tintA: 128,
tintB: 128,
tint: [-1, 0, 0, 0],
flatten: false,

@@ -262,7 +261,8 @@ flattenBackground: [0, 0, 0],

streamOut: false,
withMetadata: false,
keepMetadata: 0,
withMetadataOrientation: -1,
withMetadataDensity: 0,
withMetadataIcc: '',
withMetadataStrs: {},
withIccProfile: '',
withExif: {},
withExifMerge: true,
resolveWithObject: false,

@@ -269,0 +269,0 @@ // output format

@@ -166,31 +166,36 @@ // Copyright 2013 Lovell Fuller and others.

/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
* unless a custom output profile is provided.
* Keep all EXIF metadata from the input image in the output image.
*
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
*
* EXIF metadata is unsupported for TIFF output.
*
* @since 0.33.0
*
* @example
* sharp('input.jpg')
* .withMetadata()
* .toFile('output-with-metadata.jpg')
* .then(info => { ... });
* const outputWithExif = await sharp(inputWithExif)
* .keepExif()
* .toBuffer();
*
* @returns {Sharp}
*/
function keepExif () {
this.options.keepMetadata |= 0b00001;
return this;
}
/**
* Set EXIF metadata in the output image, ignoring any EXIF in the input image.
*
* @since 0.33.0
*
* @example
* // Set output EXIF metadata
* const data = await sharp(input)
* .withMetadata({
* exif: {
* IFD0: {
* Copyright: 'The National Gallery'
* },
* IFD3: {
* GPSLatitudeRef: 'N',
* GPSLatitude: '51/1 30/1 3230/100',
* GPSLongitudeRef: 'W',
* GPSLongitude: '0/1 7/1 4366/100'
* }
* const dataWithExif = await sharp(input)
* .withExif({
* IFD0: {
* Copyright: 'The National Gallery'
* },
* IFD3: {
* GPSLatitudeRef: 'N',
* GPSLatitude: '51/1 30/1 3230/100',
* GPSLongitudeRef: 'W',
* GPSLongitude: '0/1 7/1 4366/100'
* }

@@ -200,3 +205,144 @@ * })

*
* @param {Object<string, Object<string, string>>} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function withExif (exif) {
if (is.object(exif)) {
for (const [ifd, entries] of Object.entries(exif)) {
if (is.object(entries)) {
for (const [k, v] of Object.entries(entries)) {
if (is.string(v)) {
this.options.withExif[`exif-${ifd.toLowerCase()}-${k}`] = v;
} else {
throw is.invalidParameterError(`${ifd}.${k}`, 'string', v);
}
}
} else {
throw is.invalidParameterError(ifd, 'object', entries);
}
}
} else {
throw is.invalidParameterError('exif', 'object', exif);
}
this.options.withExifMerge = false;
return this.keepExif();
}
/**
* Update EXIF metadata from the input image in the output image.
*
* @since 0.33.0
*
* @example
* const dataWithMergedExif = await sharp(inputWithExif)
* .withExifMerge({
* IFD0: {
* Copyright: 'The National Gallery'
* }
* })
* .toBuffer();
*
* @param {Object<string, Object<string, string>>} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function withExifMerge (exif) {
this.withExif(exif);
this.options.withExifMerge = true;
return this;
}
/**
* Keep ICC profile from the input image in the output image.
*
* Where necessary, will attempt to convert the output colour space to match the profile.
*
* @since 0.33.0
*
* @example
* const outputWithIccProfile = await sharp(inputWithIccProfile)
* .keepIccProfile()
* .toBuffer();
*
* @returns {Sharp}
*/
function keepIccProfile () {
this.options.keepMetadata |= 0b01000;
return this;
}
/**
* Transform using an ICC profile and attach to the output image.
*
* This can either be an absolute filesystem path or
* built-in profile name (`srgb`, `p3`, `cmyk`).
*
* @since 0.33.0
*
* @example
* const outputWithP3 = await sharp(input)
* .withIccProfile('p3')
* .toBuffer();
*
* @param {string} icc - Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk).
* @param {Object} [options]
* @param {number} [options.attach=true] Should the ICC profile be included in the output image metadata?
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function withIccProfile (icc, options) {
if (is.string(icc)) {
this.options.withIccProfile = icc;
} else {
throw is.invalidParameterError('icc', 'string', icc);
}
this.keepIccProfile();
if (is.object(options)) {
if (is.defined(options.attach)) {
if (is.bool(options.attach)) {
if (!options.attach) {
this.options.keepMetadata &= ~0b01000;
}
} else {
throw is.invalidParameterError('attach', 'boolean', options.attach);
}
}
}
return this;
}
/**
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
*
* The default behaviour, when `keepMetadata` is not used, is to convert to the device-independent
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
*
* @since 0.33.0
*
* @example
* const outputWithMetadata = await sharp(inputWithMetadata)
* .keepMetadata()
* .toBuffer();
*
* @returns {Sharp}
*/
function keepMetadata () {
this.options.keepMetadata = 0b11111;
return this;
}
/**
* Keep most metadata (EXIF, XMP, IPTC) from the input image in the output image.
*
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate.
*
* Allows orientation and density to be set or updated.
*
* @example
* const outputSrgbWithMetadata = await sharp(inputRgbWithMetadata)
* .withMetadata()
* .toBuffer();
*
* @example
* // Set output metadata to 96 DPI

@@ -208,5 +354,3 @@ * const data = await sharp(input)

* @param {Object} [options]
* @param {number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
* @param {string} [options.icc='srgb'] Filesystem path to output ICC profile, relative to `process.cwd()`, defaults to built-in sRGB.
* @param {Object<Object>} [options.exif={}] Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
* @param {number} [options.orientation] Used to update the EXIF `Orientation` tag, integer between 1 and 8.
* @param {number} [options.density] Number of pixels per inch (DPI).

@@ -217,3 +361,4 @@ * @returns {Sharp}

function withMetadata (options) {
this.options.withMetadata = is.bool(options) ? options : true;
this.keepMetadata();
this.withIccProfile('srgb');
if (is.object(options)) {

@@ -235,26 +380,6 @@ if (is.defined(options.orientation)) {

if (is.defined(options.icc)) {
if (is.string(options.icc)) {
this.options.withMetadataIcc = options.icc;
} else {
throw is.invalidParameterError('icc', 'string filesystem path to ICC profile', options.icc);
}
this.withIccProfile(options.icc);
}
if (is.defined(options.exif)) {
if (is.object(options.exif)) {
for (const [ifd, entries] of Object.entries(options.exif)) {
if (is.object(entries)) {
for (const [k, v] of Object.entries(entries)) {
if (is.string(v)) {
this.options.withMetadataStrs[`exif-${ifd.toLowerCase()}-${k}`] = v;
} else {
throw is.invalidParameterError(`exif.${ifd}.${k}`, 'string', v);
}
}
} else {
throw is.invalidParameterError(`exif.${ifd}`, 'object', entries);
}
}
} else {
throw is.invalidParameterError('exif', 'object', options.exif);
}
this.withExifMerge(options.exif);
}

@@ -1415,2 +1540,8 @@ }

toBuffer,
keepExif,
withExif,
withExifMerge,
keepIccProfile,
withIccProfile,
keepMetadata,
withMetadata,

@@ -1417,0 +1548,0 @@ toFormat,

@@ -20,6 +20,7 @@ // Copyright 2013 Lovell Fuller and others.

let sharp;
const errors = [];
for (const path of paths) {
try {
module.exports = require(path);
sharp = require(path);
break;

@@ -33,3 +34,5 @@ } catch (err) {

/* istanbul ignore next */
if (!module.exports) {
if (sharp) {
module.exports = sharp;
} else {
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));

@@ -36,0 +39,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.0-alpha.11",
"version": "0.33.0-rc.2",
"author": "Lovell Fuller <npm@lovell.info>",

@@ -144,32 +144,32 @@ "homepage": "https://github.com/lovell/sharp",

"optionalDependencies": {
"@img/sharp-darwin-arm64": "0.33.0-alpha.11",
"@img/sharp-darwin-x64": "0.33.0-alpha.11",
"@img/sharp-libvips-darwin-arm64": "0.0.3",
"@img/sharp-libvips-darwin-x64": "0.0.3",
"@img/sharp-libvips-linux-arm": "0.0.3",
"@img/sharp-libvips-linux-arm64": "0.0.3",
"@img/sharp-libvips-linux-s390x": "0.0.3",
"@img/sharp-libvips-linux-x64": "0.0.3",
"@img/sharp-libvips-linuxmusl-arm64": "0.0.3",
"@img/sharp-libvips-linuxmusl-x64": "0.0.3",
"@img/sharp-linux-arm": "0.33.0-alpha.11",
"@img/sharp-linux-arm64": "0.33.0-alpha.11",
"@img/sharp-linux-s390x": "0.33.0-alpha.11",
"@img/sharp-linux-x64": "0.33.0-alpha.11",
"@img/sharp-linuxmusl-arm64": "0.33.0-alpha.11",
"@img/sharp-linuxmusl-x64": "0.33.0-alpha.11",
"@img/sharp-wasm32": "0.33.0-alpha.11",
"@img/sharp-win32-ia32": "0.33.0-alpha.11",
"@img/sharp-win32-x64": "0.33.0-alpha.11"
"@img/sharp-darwin-arm64": "0.33.0-rc.2",
"@img/sharp-darwin-x64": "0.33.0-rc.2",
"@img/sharp-libvips-darwin-arm64": "1.0.0",
"@img/sharp-libvips-darwin-x64": "1.0.0",
"@img/sharp-libvips-linux-arm": "1.0.0",
"@img/sharp-libvips-linux-arm64": "1.0.0",
"@img/sharp-libvips-linux-s390x": "1.0.0",
"@img/sharp-libvips-linux-x64": "1.0.0",
"@img/sharp-libvips-linuxmusl-arm64": "1.0.0",
"@img/sharp-libvips-linuxmusl-x64": "1.0.0",
"@img/sharp-linux-arm": "0.33.0-rc.2",
"@img/sharp-linux-arm64": "0.33.0-rc.2",
"@img/sharp-linux-s390x": "0.33.0-rc.2",
"@img/sharp-linux-x64": "0.33.0-rc.2",
"@img/sharp-linuxmusl-arm64": "0.33.0-rc.2",
"@img/sharp-linuxmusl-x64": "0.33.0-rc.2",
"@img/sharp-wasm32": "0.33.0-rc.2",
"@img/sharp-win32-ia32": "0.33.0-rc.2",
"@img/sharp-win32-x64": "0.33.0-rc.2"
},
"devDependencies": {
"@emnapi/runtime": "^0.43.1",
"@img/sharp-libvips-dev": "0.0.3",
"@img/sharp-libvips-dev-wasm32": "0.0.3",
"@img/sharp-libvips-win32-ia32": "0.0.3",
"@img/sharp-libvips-win32-x64": "0.0.3",
"@emnapi/runtime": "^0.44.0",
"@img/sharp-libvips-dev": "1.0.0",
"@img/sharp-libvips-dev-wasm32": "1.0.0",
"@img/sharp-libvips-win32-ia32": "1.0.0",
"@img/sharp-libvips-win32-x64": "1.0.0",
"@types/node": "*",
"async": "^3.2.5",
"cc": "^3.0.1",
"emnapi": "^0.43.1",
"emnapi": "^0.44.0",
"exif-reader": "^2.0.0",

@@ -176,0 +176,0 @@ "extract-zip": "^2.0.1",

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 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