Add features from libvips 7.40+

Load TIFF from Buffer/Stream

Interlaced PNG output no longer needs tilecache

Option to disable PNG adaptive row filtering
This commit is contained in:
Lovell Fuller
2014-11-07 15:38:41 +00:00
parent 740838b47c
commit 7537adf399
11 changed files with 183 additions and 21 deletions

View File

@@ -9,9 +9,10 @@
},
"devDependencies": {
"imagemagick": "^0.1.3",
"imagemagick-native": "^1.4.0",
"gm": "^1.16.0",
"imagemagick-native": "^1.5.0",
"gm": "^1.17.0",
"async": "^0.9.0",
"semver": "^4.1.0",
"benchmark": "^1.0.0"
},
"license": "Apache 2.0",

View File

@@ -5,6 +5,7 @@ var fs = require('fs');
var async = require('async');
var assert = require('assert');
var Benchmark = require('benchmark');
var semver = require('semver');
var imagemagick = require('imagemagick');
var imagemagickNative = require('imagemagick-native');
@@ -314,7 +315,8 @@ async.series({
},
png: function(callback) {
var inputPngBuffer = fs.readFileSync(fixtures.inputPng);
(new Benchmark.Suite('png')).add('imagemagick-file-file', {
var pngSuite = new Benchmark.Suite('png');
pngSuite.add('imagemagick-file-file', {
defer: true,
fn: function(deferred) {
imagemagick.resize({
@@ -422,7 +424,23 @@ async.series({
}
});
}
}).on('cycle', function(event) {
});
if (semver.gte(sharp.libvipsVersion(), '7.41.0')) {
pngSuite.add('sharp-withoutAdaptiveFiltering', {
defer: true,
fn: function(deferred) {
sharp(inputPngBuffer).resize(width, height).withoutAdaptiveFiltering().toBuffer(function(err, buffer) {
if (err) {
throw err;
} else {
assert.notStrictEqual(null, buffer);
deferred.resolve();
}
});
}
});
}
pngSuite.on('cycle', function(event) {
console.log(' png ' + String(event.target));
}).on('complete', function() {
callback(null, this.filter('fastest').pluck('name'));

View File

@@ -3,6 +3,8 @@
var fs = require('fs');
var assert = require('assert');
var semver = require('semver');
var sharp = require('../../index');
var fixtures = require('../fixtures');
@@ -343,9 +345,9 @@ describe('Input/output', function() {
});
describe('PNG compression level', function() {
describe('PNG output', function() {
it('valid', function(done) {
it('compression level is valid', function(done) {
var isValid = false;
try {
sharp().compressionLevel(0);
@@ -355,7 +357,7 @@ describe('Input/output', function() {
done();
});
it('invalid', function(done) {
it('compression level is invalid', function(done) {
var isValid = false;
try {
sharp().compressionLevel(-1);
@@ -365,6 +367,52 @@ describe('Input/output', function() {
done();
});
if (semver.gte(sharp.libvipsVersion(), '7.41.0')) {
it('withoutAdaptiveFiltering generates smaller file [libvips 7.41.0+]', function(done) {
// First generate with adaptive filtering
sharp(fixtures.inputPng)
.resize(320, 240)
.withoutAdaptiveFiltering(false)
.toBuffer(function(err, dataAdaptive, info) {
if (err) throw err;
assert.strictEqual(true, dataAdaptive.length > 0);
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
// Then generate without
sharp(fixtures.inputPng)
.resize(320, 240)
.withoutAdaptiveFiltering()
.toBuffer(function(err, dataWithoutAdaptive, info) {
if (err) throw err;
assert.strictEqual(true, dataWithoutAdaptive.length > 0);
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
assert.strictEqual(true, dataWithoutAdaptive.length < dataAdaptive.length);
done();
});
});
});
}
});
if (semver.gte(sharp.libvipsVersion(), '7.40.0')) {
it('Load TIFF from Buffer [libvips 7.40.0+]', function(done) {
var inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
sharp(inputTiffBuffer)
.resize(320, 240)
.jpeg()
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual('jpeg', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
done();
});
});
}
});