Compare commits

...

11 Commits

Author SHA1 Message Date
Lovell Fuller
daeebcc7dc Add epeg module to the perf tests 2013-10-19 13:39:57 +01:00
Lovell Fuller
5546a4f881 Added GraphicsMagick perf stats 2013-10-04 22:01:16 +01:00
Lovell Fuller
4aee725530 README layout clean-up 2013-10-02 23:40:32 +01:00
Lovell Fuller
f3da2284b1 Now requires livbips 7.28 or later 2013-10-02 23:37:29 +01:00
Lovell Fuller
f3cd263cb7 Replaced use of deprecated libvips im_* methods with new, shiny non-deprecated vips_* versions 2013-10-02 21:50:03 +01:00
Lovell Fuller
8443dd5122 Version bump 2013-10-02 19:35:49 +01:00
Lovell Fuller
0b7c8661fb The pkgconfig data file ends up in /usr/local when compiling libvips from source 2013-09-23 21:40:01 +01:00
Lovell Fuller
30f75bcc56 Additional performance test stats 2013-08-29 22:55:42 +01:00
Lovell Fuller
6f5125e889 Corrected order of width and height in usage docs 2013-08-26 16:21:38 +01:00
Lovell Fuller
6e3f9b04de Corrected order of width and height in usage docs 2013-08-26 16:20:43 +01:00
Lovell Fuller
b836704451 Improved performance benchmarks and usage docs 2013-08-26 16:10:48 +01:00
5 changed files with 145 additions and 63 deletions

View File

@@ -1,4 +1,4 @@
# sharp
# sharp
_adj_
@@ -7,26 +7,26 @@ _adj_
3. shrewd or astute: a sharp bargainer.
4. (Informal.) very stylish: a sharp dresser; a sharp jacket.
The typical use case for this high performance Node.js module is to convert a large JPEG image to smaller JPEG images of varying dimensions.
The typical use case for this high speed Node.js module is to convert a large JPEG image to smaller JPEG images of varying dimensions.
It is somewhat opinionated in that it only deals with JPEG images, always obeys the requested dimensions by either cropping or embedding and insists on a mild sharpen of the resulting image.
Under the hood you'll find the blazingly fast [libvips](https://github.com/jcupitt/libvips) image processing library, originally created in 1989 at Birkbeck College and currently maintained by the University of Southampton. Speed is typically 25-30% faster than the imagemagick equivalent.
Under the hood you'll find the blazingly fast [libvips](https://github.com/jcupitt/libvips) image processing library, originally created in 1989 at Birkbeck College and currently maintained by the University of Southampton.
Performance is 4x-8x faster than ImageMagick and 2x-4x faster than GraphicsMagick, based mainly on the number of CPU cores available.
## Prerequisites
Requires node-gyp and libvips-dev to build.
* Node.js v0.8+
* node-gyp
* libvips-dev 7.28+
sudo npm install -g node-gyp
sudo apt-get install libvips-dev
```
sudo npm install -g node-gyp
sudo apt-get install libvips-dev
```
Requires vips-7.xx.pc (installed with libvips-dev) to be symlinked as /usr/lib/pkgconfig/vips.pc
Ubuntu 12.04 LTS:
sudo ln -s /usr/lib/pkgconfig/vips-7.26.pc /usr/lib/pkgconfig/vips.pc
Ubuntu 13.04:
When installed as a package, please symlink `vips-7.28.pc` (or later, installed with libvips-dev) as `/usr/lib/pkgconfig/vips.pc`. To do this in Ubuntu 13.04 (64-bit), use:
sudo ln -s /usr/lib/x86_64-linux-gnu/pkgconfig/vips-7.28.pc /usr/lib/pkgconfig/vips.pc
@@ -36,28 +36,82 @@ Ubuntu 13.04:
## Usage
var sharp = require("sharp");
### crop(inputPath, outputPath, width, height, callback)
Scale and crop JPEG `inputPath` to `width` x `height` and write JPEG to `outputPath` calling `callback` when complete.
Example:
```javascript
var sharp = require("sharp");
sharp.crop("input.jpg", "output.jpg", 300, 200, function(err) {
if (err) {
throw err;
}
// output.jpg is cropped input.jpg
// output.jpg is a 300 pixels wide and 200 pixels high image
// containing a scaled and cropped version of input.jpg
});
```
### embedWhite(inputPath, outputPath, width, height, callback)
Scale and embed JPEG `inputPath` to `width` x `height` using a white canvas and write JPEG to `outputPath` calling `callback` when complete.
```javascript
sharp.embedWhite("input.jpg", "output.jpg", 200, 300, function(err) {
if (err) {
throw err;
}
// output.jpg contains input.jpg embedded with a white border
// output.jpg is a 200 pixels wide and 300 pixels high image
// containing a scaled version of input.jpg embedded on a white canvas
});
```
### embedBlack(inputPath, outputPath, width, height, callback)
Scale and embed JPEG `inputPath` to `width` x `height` using a black canvas and write JPEG to `outputPath` calling `callback` when complete.
```javascript
sharp.embedBlack("input.jpg", "output.jpg", 200, 300, function(err) {
if (err) {
throw err;
}
// output.jpg contains input.jpg embedded with a black border
// output.jpg is a 200 pixels wide and 300 pixels high image
// containing a scaled version of input.jpg embedded on a black canvas
});
```
## Testing [![Build Status](https://travis-ci.org/lovell/sharp.png?branch=master)](https://travis-ci.org/lovell/sharp)
## Testing
npm install --dev sharp
npm test
## Performance
### AMD Athlon 4x core 3.3GHz 512KB L2
* imagemagick x 5.55 ops/sec ±0.45% (31 runs sampled)
* gm x 10.31 ops/sec ±3.57% (53 runs sampled)
* epeg x 27.79 ops/sec ±0.12% (69 runs sampled)
* sharp x 31.52 ops/sec ±8.74% (80 runs sampled)
### AWS t1.micro
* imagemagick x 1.36 ops/sec ±0.96% (11 runs sampled)
* sharp x 12.42 ops/sec ±5.84% (64 runs sampled)
### AWS m1.medium
* imagemagick x 1.38 ops/sec ±0.45% (11 runs sampled)
* sharp x 12.66 ops/sec ±5.54% (65 runs sampled)
### AWS c1.medium
* imagemagick x 2.10 ops/sec ±0.67% (15 runs sampled)
* sharp x 18.97 ops/sec ±10.54% (52 runs sampled)
### AWS m3.xlarge
* imagemagick x 4.46 ops/sec ±0.33% (26 runs sampled)
* sharp x 28.89 ops/sec ±7.75% (74 runs sampled)

View File

@@ -2,7 +2,10 @@
'targets': [{
'target_name': 'sharp',
'sources': ['src/sharp.cc'],
'libraries': ['<!@(PKG_CONFIG_PATH="/usr/lib/pkgconfig" pkg-config --libs glib-2.0 vips)'],
'libraries': [
'<!@(PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" pkg-config --libs vips)',
'<!@(PKG_CONFIG_PATH="/usr/lib/pkgconfig" pkg-config --libs vips)'
],
'include_dirs': [
'/usr/include/glib-2.0',
'/usr/lib/glib-2.0/include',

View File

@@ -1,30 +1,33 @@
{
"name": "sharp",
"version": "0.0.1",
"main": "./build/Release/sharp",
"version": "0.0.4",
"main": "index.js",
"description": "High performance Node.js module to resize JPEG images using the libvips image processing library",
"repository": {
"type": "git",
"url": "git://github.com/lovell/sharp"
},
"devDependencies": {
"imagemagick": "*"
"imagemagick": "*",
"gm": "*",
"epeg": "*",
"benchmark": "*"
},
"scripts": {
"test": "node tests/perf.js"
},
"engines": {
"node": "*"
"node": ">=0.8"
},
"keywords": [
"jpeg",
"resize",
"thumbnail",
"sharpen",
"crop",
"embed",
"sharpen",
"crop",
"embed",
"libvips",
"fast"
"fast"
],
"author": "Lovell Fuller",
"license": "Apache 2.0"

View File

@@ -39,7 +39,7 @@ void ResizeAsync(uv_work_t *work) {
ResizeBaton* baton = static_cast<ResizeBaton*>(work->data);
VipsImage *in = vips_image_new_mode((baton->src).c_str(), "p");
im_jpeg2vips((baton->src).c_str(), in);
vips_jpegload((baton->src).c_str(), &in, NULL);
if (in == NULL) {
(baton->err).append(vips_error_buffer());
vips_error_clear();
@@ -114,10 +114,10 @@ void ResizeAsync(uv_work_t *work) {
}
img = t[3];
if (im_vips2jpeg(img, baton->dst.c_str())) {
if (vips_jpegsave(img, baton->dst.c_str(), "Q", 80, "profile", "none", "optimize_coding", TRUE, NULL)) {
(baton->err).append(vips_error_buffer());
vips_error_clear();
}
}
}
void ResizeAsyncAfter(uv_work_t *work, int status) {

View File

@@ -1,42 +1,64 @@
var sharp = require("../index");
var imagemagick = require("imagemagick");
var gm = require("gm");
var epeg = require("epeg");
var assert = require("assert");
var Benchmark = require("benchmark");
// http://www.flickr.com/photos/grizdave/2569067123/
var input = __dirname + "/2569067123_aca715a2ee_o.jpg";
var input = __dirname + "/2569067123_aca715a2ee_o.jpg"; // http://www.flickr.com/photos/grizdave/2569067123/
var output = __dirname + "/output.jpg";
var width = 640;
var height = 480;
// imagemagick
var time = process.hrtime();
imagemagick.resize({
srcPath: input,
dstPath: output,
quality: 0.75,
width: width,
height: height
}, function(err) {
if (err) {
throw err;
var suite = new Benchmark.Suite;
suite.add("imagemagick", {
"defer": true,
"fn": function(deferred) {
imagemagick.resize({
srcPath: input,
dstPath: output,
quality: 0.75,
width: width,
height: height
}, function(err) {
if (err) {
throw err;
} else {
deferred.resolve();
}
});
}
var diff = process.hrtime(time);
imagemagickTime = diff[0] * 1e9 + diff[1];
console.log("imagemagick took %d nanoseconds", imagemagickTime);
// sharp
time = process.hrtime();
sharp.crop(input, output, width, height, function(err) {
if (err) {
throw err;
}
diff = process.hrtime(time);
var sharpTime = diff[0] * 1e9 + diff[1];
console.log("sharp took %d nanoseconds", sharpTime);
// diff
assert(sharpTime < imagemagickTime, "sharp was blunt");
console.log("sharp was %d%% faster", (imagemagickTime - sharpTime) / imagemagickTime * 100);
});
});
}).add("gm", {
"defer": true,
"fn": function(deferred) {
gm(input).crop(width, height).write(output, function (err) {
if (err) {
throw err;
} else {
deferred.resolve();
}
});
}
}).add("epeg", {
"defer": true,
"fn": function(deferred) {
var image = new epeg.Image({path: input});
image.downsize(width, height).saveTo(output);
deferred.resolve();
}
}).add("sharp", {
"defer": true,
"fn": function(deferred) {
sharp.crop(input, output, width, height, function(err) {
if (err) {
throw err;
} else {
deferred.resolve();
}
});
}
}).on("cycle", function(event) {
console.log(String(event.target));
}).on("complete", function() {
assert(this.filter("fastest").pluck("name") == "sharp");
}).run();