Comparing version 0.7.2 to 0.8.0
116
index.js
@@ -7,2 +7,3 @@ 'use strict'; | ||
var semver = require('semver'); | ||
var color = require('color'); | ||
@@ -12,2 +13,3 @@ var BluebirdPromise = require('bluebird'); | ||
var sharp = require('./build/Release/sharp'); | ||
var libvipsVersion = sharp.libvipsVersion(); | ||
@@ -46,3 +48,6 @@ var Sharp = function(input) { | ||
flatten: false, | ||
sharpen: false, | ||
blurRadius: 0, | ||
sharpenRadius: 0, | ||
sharpenFlat: 1, | ||
sharpenJagged: 2, | ||
gamma: 0, | ||
@@ -55,2 +60,3 @@ greyscale: false, | ||
compressionLevel: 6, | ||
withoutAdaptiveFiltering: false, | ||
streamOut: false, | ||
@@ -65,10 +71,16 @@ withMetadata: false | ||
if ( | ||
(input.length > 1) && | ||
(input[0] === 0xff && input[1] === 0xd8) || // JPEG | ||
(input[0] === 0x89 && input[1] === 0x50) || // PNG | ||
(input[0] === 0x52 && input[1] === 0x49) // WebP | ||
(input.length > 3) && | ||
// JPEG | ||
(input[0] === 0xFF && input[1] === 0xD8) || | ||
// PNG | ||
(input[0] === 0x89 && input[1] === 0x50) || | ||
// WebP | ||
(input[0] === 0x52 && input[1] === 0x49) || | ||
// TIFF | ||
(input[0] === 0x4D && input[1] === 0x4D && input[2] === 0x00 && (input[3] === 0x2A || input[3] === 0x2B)) || | ||
(input[0] === 0x49 && input[1] === 0x49 && (input[2] === 0x2A || input[2] === 0x2B) && input[3] === 0x00) | ||
) { | ||
this.options.bufferIn = input; | ||
} else { | ||
throw new Error('Buffer contains an unsupported image format. JPEG, PNG and WebP are currently supported.'); | ||
throw new Error('Buffer contains an unsupported image format. JPEG, PNG, WebP and TIFF are currently supported.'); | ||
} | ||
@@ -135,12 +147,2 @@ } else { | ||
/* | ||
Deprecated embed* methods, to be removed in v0.8.0 | ||
*/ | ||
Sharp.prototype.embedWhite = util.deprecate(function() { | ||
return this.background('white').embed(); | ||
}, "embedWhite() is deprecated, use background('white').embed() instead"); | ||
Sharp.prototype.embedBlack = util.deprecate(function() { | ||
return this.background('black').embed(); | ||
}, "embedBlack() is deprecated, use background('black').embed() instead"); | ||
/* | ||
Set the background colour for embed and flatten operations. | ||
@@ -213,4 +215,20 @@ Delegates to the 'Color' module, which can throw an Error | ||
Sharp.prototype.sharpen = function(sharpen) { | ||
this.options.sharpen = (typeof sharpen === 'boolean') ? sharpen : true; | ||
/* | ||
Blur the output image. | ||
Call without a radius to use a fast, mild blur. | ||
Call with a radius to use a slower, more accurate Gaussian blur. | ||
*/ | ||
Sharp.prototype.blur = function(radius) { | ||
if (typeof radius === 'undefined') { | ||
// No arguments: default to mild blur | ||
this.options.blurRadius = -1; | ||
} else if (typeof radius === 'boolean') { | ||
// Boolean argument: apply mild blur? | ||
this.options.blurRadius = radius ? -1 : 0; | ||
} else if (typeof radius === 'number' && !Number.isNaN(radius) && (radius % 1 === 0) && radius >= 1) { | ||
// Numeric argument: specific radius | ||
this.options.blurRadius = radius; | ||
} else { | ||
throw new Error('Invalid blur radius ' + radius + ' (expected integer >= 1)'); | ||
} | ||
return this; | ||
@@ -220,2 +238,42 @@ }; | ||
/* | ||
Sharpen the output image. | ||
Call without a radius to use a fast, mild sharpen. | ||
Call with a radius to use a slow, accurate sharpen using the L of LAB colour space. | ||
radius - size of mask in pixels, must be integer | ||
flat - level of "flat" area sharpen, default 1 | ||
jagged - level of "jagged" area sharpen, default 2 | ||
*/ | ||
Sharp.prototype.sharpen = function(radius, flat, jagged) { | ||
if (typeof radius === 'undefined') { | ||
// No arguments: default to mild sharpen | ||
this.options.sharpenRadius = -1; | ||
} else if (typeof radius === 'boolean') { | ||
// Boolean argument: apply mild sharpen? | ||
this.options.sharpenRadius = radius ? -1 : 0; | ||
} else if (typeof radius === 'number' && !Number.isNaN(radius) && (radius % 1 === 0) && radius >= 1) { | ||
// Numeric argument: specific radius | ||
this.options.sharpenRadius = radius; | ||
// Control over flat areas | ||
if (typeof flat !== 'undefined' && flat !== null) { | ||
if (typeof flat === 'number' && !Number.isNaN(flat) && flat >= 0) { | ||
this.options.sharpenFlat = flat; | ||
} else { | ||
throw new Error('Invalid sharpen level for flat areas ' + flat + ' (expected >= 0)'); | ||
} | ||
} | ||
// Control over jagged areas | ||
if (typeof jagged !== 'undefined' && jagged !== null) { | ||
if (typeof jagged === 'number' && !Number.isNaN(jagged) && jagged >= 0) { | ||
this.options.sharpenJagged = jagged; | ||
} else { | ||
throw new Error('Invalid sharpen level for jagged areas ' + jagged + ' (expected >= 0)'); | ||
} | ||
} | ||
} else { | ||
throw new Error('Invalid sharpen radius ' + radius + ' (expected integer >= 1)'); | ||
} | ||
return this; | ||
}; | ||
/* | ||
Set the interpolator to use for the affine transformation | ||
@@ -280,2 +338,5 @@ */ | ||
/* | ||
zlib compression level for PNG output | ||
*/ | ||
Sharp.prototype.compressionLevel = function(compressionLevel) { | ||
@@ -290,2 +351,14 @@ if (!Number.isNaN(compressionLevel) && compressionLevel >= 0 && compressionLevel <= 9) { | ||
/* | ||
Disable the use of adaptive row filtering for PNG output - requires libvips 7.41.0+ | ||
*/ | ||
Sharp.prototype.withoutAdaptiveFiltering = function(withoutAdaptiveFiltering) { | ||
if (semver.gte(libvipsVersion, '7.41.0')) { | ||
this.options.withoutAdaptiveFiltering = (typeof withoutAdaptiveFiltering === 'boolean') ? withoutAdaptiveFiltering : true; | ||
} else { | ||
console.error('withoutAdaptiveFiltering requires libvips 7.41.0+'); | ||
} | ||
return this; | ||
}; | ||
Sharp.prototype.withMetadata = function(withMetadata) { | ||
@@ -519,1 +592,8 @@ this.options.withMetadata = (typeof withMetadata === 'boolean') ? withMetadata : true; | ||
}; | ||
/* | ||
Get the version of the libvips library | ||
*/ | ||
module.exports.libvipsVersion = function() { | ||
return libvipsVersion; | ||
}; |
{ | ||
"name": "sharp", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"author": "Lovell Fuller <npm@lovell.info>", | ||
@@ -16,3 +16,3 @@ "contributors": [ | ||
], | ||
"description": "High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library", | ||
"description": "High performance Node.js module to resize JPEG, PNG, WebP and TIFF images using the libvips library", | ||
"scripts": { | ||
@@ -40,10 +40,9 @@ "test": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=10000 ./test/unit/*.js" | ||
"vips", | ||
"fast", | ||
"buffer", | ||
"stream" | ||
], | ||
"dependencies": { | ||
"bluebird": "^2.3.10", | ||
"bluebird": "^2.3.11", | ||
"color": "^0.7.1", | ||
"nan": "^1.4.0" | ||
"nan": "^1.4.1", | ||
"semver": "^4.1.0" | ||
}, | ||
@@ -50,0 +49,0 @@ "devDependencies": { |
@@ -32,5 +32,5 @@ # sharp | ||
* Node.js v0.10+ | ||
* [libvips](https://github.com/jcupitt/libvips) v7.38.5+ | ||
* [libvips](https://github.com/jcupitt/libvips) v7.40.0+ (7.42.0+ recommended) | ||
To install the latest version of libvips on the following Operating Systems: | ||
To install the most suitable version of libvips on the following Operating Systems: | ||
@@ -42,3 +42,3 @@ * Mac OS | ||
* Debian 7, 8 | ||
* Ubuntu 12.04, 14.04, 14.10 | ||
* Ubuntu 12.04, 14.04, 14.10, 15.04 | ||
* Mint 13, 17 | ||
@@ -219,3 +219,3 @@ * Red Hat Linux | ||
* Buffer containing JPEG, PNG or WebP image data, or | ||
* Buffer containing JPEG, PNG, WebP or TIFF image data, or | ||
* String containing the filename of an image, with most major formats supported. | ||
@@ -225,3 +225,3 @@ | ||
JPEG, PNG or WebP format image data can be streamed into the object when `input` is not provided. | ||
JPEG, PNG, WebP or TIFF format image data can be streamed into the object when `input` is not provided. | ||
@@ -239,3 +239,3 @@ JPEG, PNG or WebP format image data can be streamed out from this object. | ||
* `height`: Number of pixels high | ||
* `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `scrgb`, `cmyk`, `lab`, `xyz`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L502) | ||
* `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `scrgb`, `cmyk`, `lab`, `xyz`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L522) | ||
* `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK | ||
@@ -327,6 +327,20 @@ * `hasAlpha`: Boolean indicating the presence of an alpha transparency channel | ||
#### sharpen() | ||
#### blur([radius]) | ||
Perform a mild sharpen of the output image. This typically reduces performance by 10%. | ||
When used without parameters, performs a fast, mild blur of the output image. This typically reduces performance by 10%. | ||
When a `radius` is provided, performs a slower, more accurate Gaussian blur. This typically reduces performance by 30%. | ||
* `radius`, if present, is an integral Number representing the approximate blur mask radius in pixels. | ||
#### sharpen([radius], [flat], [jagged]) | ||
When used without parameters, performs a fast, mild sharpen of the output image. This typically reduces performance by 10%. | ||
When a `radius` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space. Separate control over the level of sharpening in "flat" and "jagged" areas is available. This typically reduces performance by 50%. | ||
* `radius`, if present, is an integral Number representing the sharpen mask radius in pixels. | ||
* `flat`, if present, is a Number representing the level of sharpening to apply to "flat" areas, defaulting to a value of 1.0. | ||
* `jagged`, if present, is a Number representing the level of sharpening to apply to "jagged" areas, defaulting to a value of 2.0. | ||
#### interpolateWith(interpolator) | ||
@@ -397,2 +411,8 @@ | ||
#### withoutAdaptiveFiltering() | ||
_Requires libvips 7.41.0+_ | ||
An advanced and experimental PNG output setting to disable adaptive row filtering. | ||
### Output methods | ||
@@ -399,0 +419,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
661334
548
612
4
17
+ Addedsemver@^4.1.0
+ Addedsemver@4.3.6(transitive)
Updatedbluebird@^2.3.11
Updatednan@^1.4.1