mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Use libvips' new lanczos3 kernel as default for image reduce
Deprecate interpolateWith method, now provided as an option
This commit is contained in:
@@ -45,15 +45,17 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
|
||||
it('Flatten 16-bit PNG with transparency to orange', function(done) {
|
||||
var output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.flatten()
|
||||
.background({r: 255, g: 102, b: 0})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toFile(output, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual(32, info.width);
|
||||
assert.strictEqual(32, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('flatten-rgb16-orange.jpg'), data, { threshold: 6 }, done);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('flatten-rgb16-orange.jpg'), 25);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('Clone', function() {
|
||||
var rotator = sharp().rotate(90);
|
||||
// Cloned instances with differing dimensions
|
||||
rotator.clone().resize(320, 240).pipe(writable1);
|
||||
rotator.clone().resize(100).pipe(writable2);
|
||||
rotator.clone().resize(100, 122).pipe(writable2);
|
||||
// Go
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||
});
|
||||
|
||||
@@ -5,100 +5,67 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
describe('Interpolation', function() {
|
||||
describe('Interpolators and kernels', function() {
|
||||
|
||||
it('nearest neighbour', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.nearest)
|
||||
.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();
|
||||
describe('Reducers', function() {
|
||||
[
|
||||
sharp.kernel.cubic,
|
||||
sharp.kernel.lanczos2,
|
||||
sharp.kernel.lanczos3
|
||||
].forEach(function(kernel) {
|
||||
it(kernel, function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, null, { kernel: kernel })
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('bilinear', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.bilinear)
|
||||
.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();
|
||||
describe('Enlargers', function() {
|
||||
[
|
||||
sharp.interpolator.nearest,
|
||||
sharp.interpolator.bilinear,
|
||||
sharp.interpolator.bicubic,
|
||||
sharp.interpolator.nohalo,
|
||||
sharp.interpolator.locallyBoundedBicubic,
|
||||
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
||||
].forEach(function(interpolator) {
|
||||
it(interpolator, function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, null, { interpolator: interpolator })
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('bicubic', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.bicubic)
|
||||
.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();
|
||||
});
|
||||
it('unknown kernel throws', function() {
|
||||
assert.throws(function() {
|
||||
sharp().resize(null, null, { kernel: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
it('nohalo', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.nohalo)
|
||||
.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();
|
||||
});
|
||||
it('unknown interpolator throws', function() {
|
||||
assert.throws(function() {
|
||||
sharp().resize(null, null, { interpolator: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
it('locally bounded bicubic (LBB)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.locallyBoundedBicubic)
|
||||
.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();
|
||||
});
|
||||
describe('deprecated interpolateWith method still works', function() {
|
||||
it('resize then interpolateWith', function() {
|
||||
sharp().resize(1, 1).interpolateWith('bicubic');
|
||||
});
|
||||
it('interpolateWith then resize', function() {
|
||||
sharp().interpolateWith('bicubic').resize(1, 1);
|
||||
});
|
||||
});
|
||||
|
||||
it('vertex split quadratic basis spline (VSQBS)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.interpolateWith(sharp.interpolator.vertexSplitQuadraticBasisSpline)
|
||||
.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();
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown interpolator throws', function(done) {
|
||||
var isValid = false;
|
||||
try {
|
||||
sharp().interpolateWith('nonexistant');
|
||||
isValid = true;
|
||||
} catch (e) {}
|
||||
assert(!isValid);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1028,14 +1028,14 @@ describe('Input/output', function() {
|
||||
it('Info event data', function(done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
var inPipeline = sharp()
|
||||
.resize(840)
|
||||
.resize(840, 472)
|
||||
.raw()
|
||||
.on('info', function(info) {
|
||||
assert.strictEqual(840, info.width);
|
||||
assert.strictEqual(472, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
});
|
||||
var badPipeline = sharp(null, {raw: {width: 840, height: 473, channels: 3}})
|
||||
var badPipeline = sharp(null, {raw: {width: 840, height: 500, channels: 3}})
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
||||
@@ -1047,7 +1047,7 @@ describe('Input/output', function() {
|
||||
done();
|
||||
});
|
||||
inPipeline = sharp()
|
||||
.resize(840)
|
||||
.resize(840, 472)
|
||||
.raw();
|
||||
readable.pipe(inPipeline).pipe(goodPipeline);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('Threshold', function() {
|
||||
.threshold()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, { threshold: 14 }, done);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user