Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.4.2 to 0.5.0

83

index.js
/*jslint node: true */
'use strict';
var Promise = require('bluebird');
var sharp = require('./build/Release/sharp');

@@ -14,2 +15,4 @@

canvas: 'c',
angle: 0,
withoutEnlargement: false,
sharpen: false,

@@ -23,5 +26,9 @@ progressive: false,

if (typeof input === 'string') {
this.options.inFile = input;
this.options.fileIn = input;
} else if (typeof input ==='object' && input instanceof Buffer) {
this.options.inBuffer = input;
if (input.length > 0) {
this.options.bufferIn = input;
} else {
throw 'Buffer is empty';
}
} else {

@@ -54,3 +61,27 @@ throw 'Unsupported input ' + typeof input;

/*
Rotate output image by 0, 90, 180 or 270 degrees
Auto-rotation based on the EXIF Orientation tag is represented by an angle of -1
*/
Sharp.prototype.rotate = function(angle) {
if (typeof angle === 'undefined') {
this.options.angle = -1;
} else if (!Number.isNaN(angle) && [0, 90, 180, 270].indexOf(angle) !== -1) {
this.options.angle = angle;
} else {
throw 'Unsupport angle (0, 90, 180, 270) ' + angle;
}
return this;
};
/*
Do not enlarge the output if the input width *or* height are already less than the required dimensions
This is equivalent to GraphicsMagick's ">" geometry option:
"change the dimensions of the image only if its width or height exceeds the geometry specification"
*/
Sharp.prototype.withoutEnlargement = function(withoutEnlargement) {
this.options.withoutEnlargement = (typeof withoutEnlargement === 'boolean') ? withoutEnlargement : true;
return this;
};
Sharp.prototype.sharpen = function(sharpen) {

@@ -111,10 +142,13 @@ this.options.sharpen = (typeof sharpen === 'boolean') ? sharpen : true;

Sharp.prototype.write = function(output, callback) {
/*
Write output image data to a file
*/
Sharp.prototype.toFile = function(output, callback) {
if (!output || output.length === 0) {
callback('Invalid output');
} else {
if (this.options.inFile === output) {
if (this.options.fileIn === output) {
callback('Cannot use same file for input and output');
} else {
this._sharp(output, callback);
return this._sharp(output, callback);
}

@@ -125,2 +159,5 @@ }

// Deprecated to make way for future stream support - remove in v0.6.0
Sharp.prototype.write = Sharp.prototype.toFile;
Sharp.prototype.toBuffer = function(callback) {

@@ -142,18 +179,24 @@ return this._sharp('__input', callback);

/*
Invoke the C++ image processing pipeline
Supports callback and promise variants
*/
Sharp.prototype._sharp = function(output, callback) {
sharp.resize(
this.options.inFile,
this.options.inBuffer,
output,
this.options.width,
this.options.height,
this.options.canvas,
this.options.sharpen,
this.options.progressive,
this.options.sequentialRead,
this.options.quality,
this.options.compressionLevel,
callback
);
return this;
if (typeof callback === 'function') {
// I like callbacks
sharp.resize(this.options, output, callback);
return this;
} else {
// I like promises
var options = this.options;
return new Promise(function(resolve, reject) {
sharp.resize(options, output, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
};

@@ -160,0 +203,0 @@

{
"name": "sharp",
"version": "0.4.2",
"version": "0.5.0",
"author": "Lovell Fuller <npm@lovell.info>",

@@ -34,3 +34,4 @@ "contributors": [

"dependencies": {
"nan": "^1.1.0"
"nan": "^1.1.2",
"bluebird": "^1.2.4"
},

@@ -37,0 +38,0 @@ "devDependencies": {

@@ -12,3 +12,3 @@ # sharp

The performance of JPEG resizing is typically 8x faster than ImageMagick and GraphicsMagick, based mainly on the number of CPU cores available. Everything remains non-blocking thanks to _libuv_.
The performance of JPEG resizing is typically 8x faster than ImageMagick and GraphicsMagick, based mainly on the number of CPU cores available. Everything remains non-blocking thanks to _libuv_ and Promises/A+ are supported.

@@ -32,3 +32,3 @@ This module supports reading and writing images of JPEG, PNG and WebP to and from both Buffer objects and the filesystem. It also supports reading images of many other types from the filesystem via libmagick++ or libgraphicsmagick++ if present.

_libvips_ will take advantage of [liborc](http://code.entropywave.com/orc/) if present, however versions of _liborc_ prior to 0.4.19 suffer memory leaks.
_libvips_ can take advantage of [liborc](http://code.entropywave.com/orc/) if present. Warning: versions of _liborc_ prior to 0.4.19 suffer [memory leaks](https://github.com/lovell/sharp/issues/21#issuecomment-42367306) and version 0.4.19 suffers [buffer overflows](https://github.com/lovell/sharp/issues/21#issuecomment-44813498).

@@ -53,3 +53,3 @@ ### Install libvips on Mac OS

sudo apt-get install automake build-essential git gobject-introspection gtk-doc-tools libfftw3-dev libglib2.0-dev libjpeg-turbo8-dev libpng12-dev libwebp-dev libtiff5-dev libxml2-dev swig
sudo apt-get install automake build-essential git gobject-introspection gtk-doc-tools libfftw3-dev libglib2.0-dev libjpeg-turbo8-dev libpng12-dev libwebp-dev libtiff5-dev libexif-dev libxml2-dev swig
git clone https://github.com/jcupitt/libvips.git

@@ -66,3 +66,3 @@ cd libvips

Requires `libtiff4-dev` instead of `libtiff5-dev` and has [a bug](https://bugs.launchpad.net/ubuntu/+source/libwebp/+bug/1108731) in the libwebp package. Work around these problems by running these command first:
Requires `libtiff4-dev` instead of `libtiff5-dev` and has [a bug](https://bugs.launchpad.net/ubuntu/+source/libwebp/+bug/1108731) in the libwebp package. Work around these problems by running these commands first:

@@ -82,3 +82,3 @@ sudo add-apt-repository ppa:lyrasis/precise-backports

```javascript
sharp('input.jpg').resize(300, 200).write('output.jpg', function(err) {
sharp('input.jpg').resize(300, 200).toFile('output.jpg', function(err) {
if (err) {

@@ -93,7 +93,7 @@ throw err;

```javascript
sharp('input.jpg').resize(null, 200).progressive().toBuffer(function(err, outputBuffer) {
sharp('input.jpg').rotate().resize(null, 200).progressive().toBuffer(function(err, outputBuffer) {
if (err) {
throw err;
}
// outputBuffer contains progressive JPEG image data, 200 pixels high
// outputBuffer contains 200px high progressive JPEG image data, auto-rotated using EXIF Orientation tag
});

@@ -103,7 +103,4 @@ ```

```javascript
sharp('input.png').resize(300).sharpen().quality(90).webp(function(err, outputBuffer) {
if (err) {
throw err;
}
// outputBuffer contains 300 pixels wide, sharpened, 90% quality WebP image data
sharp('input.png').rotate(180).resize(300).sharpen().quality(90).webp().then(function(outputBuffer) {
// outputBuffer contains 300px wide, upside down, sharpened, 90% quality WebP image data
});

@@ -113,6 +110,3 @@ ```

```javascript
sharp(inputBuffer).resize(200, 300).embedWhite().write('output.tiff', function(err) {
if (err) {
throw err;
}
sharp(inputBuffer).resize(200, 300).embedWhite().toFile('output.tiff').then(function() {
// output.tiff is a 200 pixels wide and 300 pixels high image containing a scaled

@@ -134,6 +128,3 @@ // version, embedded on a white canvas, of the image data in buffer

```javascript
sharp(inputBuffer).resize(200, 200).max().jpeg(function(err, outputBuffer) {
if (err) {
throw err;
}
sharp(inputBuffer).resize(200, 200).max().jpeg().then(function(outputBuffer) {
// outputBuffer contains JPEG image data no wider than 200 pixels and no higher

@@ -155,3 +146,3 @@ // than 200 pixels regardless of the inputBuffer image dimensions

Scale to `width` x `height`. By default, the resized image is cropped to the exact size specified.
Scale output to `width` x `height`. By default, the resized image is cropped to the exact size specified.

@@ -180,2 +171,16 @@ `width` is the Number of pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.

### rotate([angle])
Rotate the output image by either an explicit angle or auto-orient based on the EXIF `Orientation` tag. Mirroring is not supported.
`angle`, if present, is a Number with a value of `0`, `90`, `180` or `270`.
Use this method without `angle` to determine the angle from EXIF data.
### withoutEnlargement()
Do not enlarge the output image if the input image width *or* height are already less than the required dimensions.
This is equivalent to GraphicsMagick's `>` geometry option: "change the dimensions of the image only if its width or height exceeds the geometry specification".
### sharpen()

@@ -205,14 +210,26 @@

### write(filename, callback)
### toFile(filename, [callback])
`filename` is a String containing the filename to write the image data to. The format is inferred from the extension, with JPEG, PNG, WebP and TIFF supported.
`callback` is called with a single argument `(err)` containing an error message, if any.
`callback`, if present, is called with a single argument `(err)` containing an error message, if any.
### jpeg(callback)
A Promises/A+ promise is returned when `callback` is not provided.
### toBuffer([callback])
Write image data to a Buffer, the format of which will match the input image. JPEG, PNG and WebP are supported.
`callback`, if present, gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant image data.
A Promises/A+ promise is returned when `callback` is not provided.
### jpeg([callback])
Write JPEG image data to a Buffer.
`callback` gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant JPEG image data.
`callback`, if present, gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant JPEG image data.
A Promises/A+ promise is returned when `callback` is not provided.
### png(callback)

@@ -222,16 +239,14 @@

`callback` gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant PNG image data.
`callback`, if present, gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant PNG image data.
### webp(callback)
A Promises/A+ promise is returned when `callback` is not provided.
### webp([callback])
Write WebP image data to a Buffer.
`callback` gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant WebP image data.
`callback`, if present, gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant WebP image data.
### toBuffer(callback)
A Promises/A+ promise is returned when `callback` is not provided.
Write image data to a Buffer, the format of which will match the input image. JPEG, PNG and WebP are supported.
`callback` gets two arguments `(err, buffer)` where `err` is an error message, if any, and `buffer` is the resultant image data.
### sharp.cache([limit])

@@ -238,0 +253,0 @@

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