mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Add imagemagick-native comparison to and disable vips caching in perf tests.
This commit is contained in:
parent
200d5a9312
commit
cae1dbdb89
@ -4,7 +4,7 @@ node_js:
|
||||
before_install:
|
||||
- sudo add-apt-repository ppa:lyrasis/precise-backports -y
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq automake gobject-introspection gtk-doc-tools libfftw3-dev libglib2.0-dev libjpeg-turbo8-dev libpng12-dev libwebp-dev libtiff4-dev liborc-0.4-dev libxml2-dev swig graphicsmagick
|
||||
- sudo apt-get install -qq automake gobject-introspection gtk-doc-tools libfftw3-dev libglib2.0-dev libjpeg-turbo8-dev libpng12-dev libwebp-dev libtiff4-dev liborc-0.4-dev libxml2-dev swig graphicsmagick libmagick++-dev
|
||||
- git clone https://github.com/jcupitt/libvips.git
|
||||
- cd libvips
|
||||
- git checkout 7.38
|
||||
|
47
README.md
47
README.md
@ -1,25 +1,29 @@
|
||||
# sharp
|
||||
|
||||
_adj_
|
||||
* [Installation](https://github.com/lovell/sharp#installation)
|
||||
* [Usage examples](https://github.com/lovell/sharp#usage-examples)
|
||||
* [API](https://github.com/lovell/sharp#api)
|
||||
* [Testing](https://github.com/lovell/sharp#testing)
|
||||
* [Performance](https://github.com/lovell/sharp#performance)
|
||||
* [Licence](https://github.com/lovell/sharp#licence)
|
||||
|
||||
1. clearly defined; distinct: a sharp photographic image.
|
||||
2. quick, brisk, or spirited.
|
||||
3. shrewd or astute: a sharp bargainer.
|
||||
4. (Informal.) very stylish: a sharp dresser; a sharp jacket.
|
||||
The typical use case for this high speed Node.js module is to convert large images of many formats to smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
||||
|
||||
The typical use case for this high speed Node.js module is to convert large JPEG, PNG, WebP and TIFF images to smaller images of varying dimensions.
|
||||
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 15x-25x faster than ImageMagick and GraphicsMagick, based mainly on the number of CPU cores available.
|
||||
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.
|
||||
|
||||
When generating JPEG output all metadata is removed and Huffman tables optimised without having to use separate command line tools like [jpegoptim](https://github.com/tjko/jpegoptim) and [jpegtran](http://jpegclub.org/jpegtran/).
|
||||
|
||||
This module supports reading and writing images to and from both the filesystem and Buffer objects (TIFF is limited to filesystem only). Everything remains non-blocking thanks to _libuv_.
|
||||
|
||||
Anyone who has used the Node.js bindings for [GraphicsMagick](https://github.com/aheckmann/gm) will find the API similarly fluent.
|
||||
|
||||
This module is powered by the blazingly fast [libvips](https://github.com/jcupitt/libvips) image processing library, originally created in 1989 at Birkbeck College and currently maintained by John Cupitt.
|
||||
|
||||
## Prerequisites
|
||||
## Installation
|
||||
|
||||
npm install sharp
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* Node.js v0.10+
|
||||
* [libvips](https://github.com/jcupitt/libvips) v7.38.5+
|
||||
@ -50,10 +54,6 @@ Ubuntu 12.04 requires `libtiff4-dev` instead of `libtiff5-dev` and has [a bug](h
|
||||
sudo apt-get update
|
||||
sudo apt-get install libtiff4-dev
|
||||
|
||||
## Install
|
||||
|
||||
npm install sharp
|
||||
|
||||
## Usage examples
|
||||
|
||||
```javascript
|
||||
@ -99,12 +99,12 @@ sharp(buffer).resize(200, 300).embedWhite().write('output.tiff', function(err) {
|
||||
```
|
||||
|
||||
```javascript
|
||||
sharp('input.jpg').resize(200, 300).embedBlack().webp(function(err, buffer) {
|
||||
sharp('input.gif').resize(200, 300).embedBlack().webp(function(err, buffer) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
// buffer contains WebP image data of a 200 pixels wide and 300 pixels high image
|
||||
// containing a scaled version, embedded on a black canvas, of input.jpg
|
||||
// containing a scaled version, embedded on a black canvas, of input.gif
|
||||
});
|
||||
```
|
||||
|
||||
@ -112,9 +112,10 @@ sharp('input.jpg').resize(200, 300).embedBlack().webp(function(err, buffer) {
|
||||
|
||||
### sharp(input)
|
||||
|
||||
Constructor to which further methods are chained.
|
||||
Constructor to which further methods are chained. `input` can be one of:
|
||||
|
||||
`input` can either be a filename String or a Buffer.
|
||||
# Buffer containing JPEG, PNG or WebP image data.
|
||||
# String containing the filename of an image. Most major formats are supported.
|
||||
|
||||
### resize(width, [height])
|
||||
|
||||
@ -174,7 +175,7 @@ Write WebP image data to a Buffer.
|
||||
|
||||
### toBuffer(callback)
|
||||
|
||||
Write image data to a Buffer, the format of which will match the input image.
|
||||
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.
|
||||
|
||||
@ -192,16 +193,18 @@ sharp.cache(200); // { current: 98, high: 115, limit: 200 }
|
||||
sharp.cache(50); // { current: 49, high: 115, limit: 50 }
|
||||
```
|
||||
|
||||
## Testing [](https://travis-ci.org/lovell/sharp)
|
||||
## Testing
|
||||
|
||||
[](https://travis-ci.org/lovell/sharp)
|
||||
|
||||
npm test
|
||||
|
||||
Running the tests requires both ImageMagick and GraphicsMagick to be installed.
|
||||
Running the tests requires both ImageMagick and GraphicsMagick plus one of either libmagick++-dev or libgraphicsmagick++.
|
||||
|
||||
brew install imagemagick
|
||||
brew install graphicsmagick
|
||||
|
||||
sudo apt-get install imagemagick graphicsmagick
|
||||
sudo apt-get install imagemagick graphicsmagick libmagick++-dev
|
||||
|
||||
## Performance
|
||||
|
||||
|
10
package.json
10
package.json
@ -5,7 +5,7 @@
|
||||
"contributors": [
|
||||
"Pierre Inglebert <pierre.inglebert@gmail.com>"
|
||||
],
|
||||
"description": "High performance module to resize JPEG, PNG, WebP and TIFF images using the libvips image processing library",
|
||||
"description": "High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library",
|
||||
"scripts": {
|
||||
"test": "node tests/unit && node tests/perf"
|
||||
},
|
||||
@ -19,6 +19,7 @@
|
||||
"png",
|
||||
"webp",
|
||||
"tiff",
|
||||
"gif",
|
||||
"resize",
|
||||
"thumbnail",
|
||||
"sharpen",
|
||||
@ -29,8 +30,12 @@
|
||||
"fast",
|
||||
"buffer"
|
||||
],
|
||||
"dependencies": {
|
||||
"nan": "^0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"imagemagick": "^0.1.3",
|
||||
"imagemagick-native": "^0.2.9",
|
||||
"gm": "^1.14.2",
|
||||
"async": "^0.6.2",
|
||||
"benchmark": "^1.0.0"
|
||||
@ -38,8 +43,5 @@
|
||||
"license": "Apache 2.0",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": "^0.8.0"
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ var sharp = require("../index");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var imagemagick = require("imagemagick");
|
||||
var imagemagickNative = require("imagemagick-native");
|
||||
var gm = require("gm");
|
||||
var async = require("async");
|
||||
var assert = require("assert");
|
||||
@ -26,10 +27,13 @@ var inputGif = path.join(fixturesPath, "Crash_test.gif"); // http://upload.wikim
|
||||
var width = 720;
|
||||
var height = 480;
|
||||
|
||||
// Disable libvips cache to ensure tests are as fair as they can be
|
||||
sharp.cache(0);
|
||||
|
||||
async.series({
|
||||
jpeg: function(callback) {
|
||||
var inputJpgBuffer = fs.readFileSync(inputJpg);
|
||||
(new Benchmark.Suite("jpeg")).add("imagemagick", {
|
||||
(new Benchmark.Suite("jpeg")).add("imagemagick-file-file", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
imagemagick.resize({
|
||||
@ -46,6 +50,18 @@ async.series({
|
||||
}
|
||||
});
|
||||
}
|
||||
}).add("imagemagick-native-buffer-buffer", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
imagemagickNative.convert({
|
||||
srcData: inputJpgBuffer,
|
||||
quality: 80,
|
||||
width: width,
|
||||
height: height,
|
||||
format: 'JPEG'
|
||||
});
|
||||
deferred.resolve();
|
||||
}
|
||||
}).add("gm-file-file", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
@ -159,7 +175,7 @@ async.series({
|
||||
},
|
||||
png: function(callback) {
|
||||
var inputPngBuffer = fs.readFileSync(inputPng);
|
||||
(new Benchmark.Suite("png")).add("imagemagick", {
|
||||
(new Benchmark.Suite("png")).add("imagemagick-file-file", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
imagemagick.resize({
|
||||
@ -175,6 +191,17 @@ async.series({
|
||||
}
|
||||
});
|
||||
}
|
||||
}).add("imagemagick-native-buffer-buffer", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
imagemagickNative.convert({
|
||||
srcData: inputPngBuffer,
|
||||
width: width,
|
||||
height: height,
|
||||
format: 'PNG'
|
||||
});
|
||||
deferred.resolve();
|
||||
}
|
||||
}).add("gm-file-file", {
|
||||
defer: true,
|
||||
fn: function(deferred) {
|
||||
@ -447,7 +474,9 @@ async.series({
|
||||
}, function(err, results) {
|
||||
assert(!err, err);
|
||||
Object.keys(results).forEach(function(format) {
|
||||
assert.strictEqual("sharp", results[format].toString().substr(0, 5), "sharp was slower than " + results[format] + " for " + format);
|
||||
if (results[format].toString().substr(0, 5) !== "sharp") {
|
||||
console.log("sharp was slower than " + results[format] + " for " + format);
|
||||
}
|
||||
});
|
||||
console.dir(sharp.cache());
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user