Use image fingerprints in functional tests #122
@ -669,6 +669,10 @@ A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUT
|
|||||||
|
|
||||||
### Functional tests
|
### Functional tests
|
||||||
|
|
||||||
|
Where possible, the functional tests use gradient-based perceptual hashes
|
||||||
|
based on [dHash](http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html)
|
||||||
|
to compare expected vs actual images.
|
||||||
|
|
||||||
#### Coverage
|
#### Coverage
|
||||||
|
|
||||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||||
|
BIN
test/fixtures/expected/exif-5.jpg
vendored
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
test/fixtures/expected/exif-8.jpg
vendored
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
test/fixtures/expected/extract-resize-crop-extract.jpg
vendored
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
test/fixtures/expected/extract-resize.jpg
vendored
Normal file
After Width: | Height: | Size: 506 B |
BIN
test/fixtures/expected/extract-rotate.jpg
vendored
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
test/fixtures/expected/extract.jpg
vendored
Normal file
After Width: | Height: | Size: 348 B |
BIN
test/fixtures/expected/extract.png
vendored
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
test/fixtures/expected/extract.tiff
vendored
Normal file
BIN
test/fixtures/expected/extract.webp
vendored
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
test/fixtures/expected/flatten-black.jpg
vendored
Normal file
After Width: | Height: | Size: 996 B |
BIN
test/fixtures/expected/flatten-orange.jpg
vendored
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
test/fixtures/expected/flip-and-flop.jpg
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/flip.jpg
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/flop.jpg
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/gravity-center.jpg
vendored
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
test/fixtures/expected/gravity-centre.jpg
vendored
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
test/fixtures/expected/gravity-east.jpg
vendored
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
test/fixtures/expected/gravity-north.jpg
vendored
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
test/fixtures/expected/gravity-south.jpg
vendored
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
test/fixtures/expected/gravity-west.jpg
vendored
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
test/fixtures/expected/resize-crop-extract.jpg
vendored
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
test/fixtures/expected/rotate-extract.jpg
vendored
Normal file
After Width: | Height: | Size: 1.6 KiB |
57
test/fixtures/index.js
vendored
@ -1,11 +1,42 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var sharp = require('../../index');
|
||||||
|
|
||||||
var getPath = function(filename) {
|
var getPath = function(filename) {
|
||||||
return path.join(__dirname, filename);
|
return path.join(__dirname, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Generates a 64-bit-as-binary-string image fingerprint
|
||||||
|
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
||||||
|
var fingerprint = function(image, done) {
|
||||||
|
sharp(image)
|
||||||
|
.greyscale()
|
||||||
|
.normalise()
|
||||||
|
.resize(9, 8)
|
||||||
|
.ignoreAspectRatio()
|
||||||
|
.interpolateWith(sharp.interpolator.vertexSplitQuadraticBasisSpline)
|
||||||
|
.raw()
|
||||||
|
.toBuffer(function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
done(err);
|
||||||
|
} else {
|
||||||
|
var fingerprint = '';
|
||||||
|
for (var col = 0; col < 8; col++) {
|
||||||
|
var gradient = 0;
|
||||||
|
for (var row = 0; row < 8; row++) {
|
||||||
|
var left = data[row * 8 + col];
|
||||||
|
var right = data[row * 8 + col + 1];
|
||||||
|
fingerprint = fingerprint + (left < right ? '1' : '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done(null, fingerprint);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
inputJpg: getPath('2569067123_aca715a2ee_o.jpg'), // http://www.flickr.com/photos/grizdave/2569067123/
|
inputJpg: getPath('2569067123_aca715a2ee_o.jpg'), // http://www.flickr.com/photos/grizdave/2569067123/
|
||||||
@ -35,6 +66,30 @@ module.exports = {
|
|||||||
outputWebP: getPath('output.webp'),
|
outputWebP: getPath('output.webp'),
|
||||||
outputZoinks: getPath('output.zoinks'), // an 'unknown' file extension
|
outputZoinks: getPath('output.zoinks'), // an 'unknown' file extension
|
||||||
|
|
||||||
path: getPath // allows tests to write files to fixtures directory (for testing with human eyes)
|
// Path for tests requiring human inspection
|
||||||
|
path: getPath,
|
||||||
|
|
||||||
|
// Path for expected output images
|
||||||
|
expected: function(filename) {
|
||||||
|
return getPath(path.join('expected', filename));
|
||||||
|
},
|
||||||
|
|
||||||
|
// Verify similarity of expected vs actual images via fingerprint
|
||||||
|
assertSimilar: function(expectedImage, actualImage, done) {
|
||||||
|
fingerprint(expectedImage, function(err, expectedFingerprint) {
|
||||||
|
if (err) throw err;
|
||||||
|
fingerprint(actualImage, function(err, actualFingerprint) {
|
||||||
|
if (err) throw err;
|
||||||
|
var distance = 0;
|
||||||
|
for (var i = 0; i < 64; i++) {
|
||||||
|
if (expectedFingerprint[i] !== actualFingerprint[i]) {
|
||||||
|
distance++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.strictEqual(true, distance <= 5); // ~7% threshold
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,12 @@ describe('Alpha transparency', function() {
|
|||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten()
|
.flatten()
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toFile(fixtures.path('output.flatten-black.jpg'), done);
|
.toBuffer(function(err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(400, info.width);
|
||||||
|
assert.strictEqual(300, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('flatten-black.jpg'), data, done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to RGB orange', function(done) {
|
it('Flatten to RGB orange', function(done) {
|
||||||
@ -21,7 +26,12 @@ describe('Alpha transparency', function() {
|
|||||||
.flatten()
|
.flatten()
|
||||||
.background({r: 255, g: 102, b: 0})
|
.background({r: 255, g: 102, b: 0})
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toFile(fixtures.path('output.flatten-rgb-orange.jpg'), done);
|
.toBuffer(function(err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(400, info.width);
|
||||||
|
assert.strictEqual(300, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('flatten-orange.jpg'), data, done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to CSS/hex orange', function(done) {
|
it('Flatten to CSS/hex orange', function(done) {
|
||||||
@ -29,7 +39,12 @@ describe('Alpha transparency', function() {
|
|||||||
.flatten()
|
.flatten()
|
||||||
.background('#ff6600')
|
.background('#ff6600')
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toFile(fixtures.path('output.flatten-hex-orange.jpg'), done);
|
.toBuffer(function(err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(400, info.width);
|
||||||
|
assert.strictEqual(300, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('flatten-orange.jpg'), data, done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not flatten', function(done) {
|
it('Do not flatten', function(done) {
|
||||||
|
@ -13,11 +13,11 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.crop(sharp.gravity.north)
|
.crop(sharp.gravity.north)
|
||||||
.toFile(fixtures.path('output.gravity-north.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-north.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -25,11 +25,11 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
.crop(sharp.gravity.east)
|
.crop(sharp.gravity.east)
|
||||||
.toFile(fixtures.path('output.gravity-east.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(320, info.height);
|
assert.strictEqual(320, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-east.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.crop(sharp.gravity.south)
|
.crop(sharp.gravity.south)
|
||||||
.toFile(fixtures.path('output.gravity-south.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-south.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
.crop(sharp.gravity.west)
|
.crop(sharp.gravity.west)
|
||||||
.toFile(fixtures.path('output.gravity-west.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(320, info.height);
|
assert.strictEqual(320, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-west.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,11 +61,11 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.crop(sharp.gravity.center)
|
.crop(sharp.gravity.center)
|
||||||
.toFile(fixtures.path('output.gravity-center.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-center.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,23 +73,18 @@ describe('Crop gravities', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
.crop(sharp.gravity.centre)
|
.crop(sharp.gravity.centre)
|
||||||
.toFile(fixtures.path('output.gravity-centre.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(320, info.height);
|
assert.strictEqual(320, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('gravity-centre.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid', function(done) {
|
it('Invalid', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).crop(5);
|
sharp(fixtures.inputJpg).crop(5);
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -12,22 +12,22 @@ describe('Partial image extraction', function() {
|
|||||||
it('JPEG', function(done) {
|
it('JPEG', function(done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract(2, 2, 20, 20)
|
.extract(2, 2, 20, 20)
|
||||||
.toFile(fixtures.path('output.extract.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(20, info.width);
|
assert.strictEqual(20, info.width);
|
||||||
assert.strictEqual(20, info.height);
|
assert.strictEqual(20, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function(done) {
|
it('PNG', function(done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.extract(300, 200, 400, 200)
|
.extract(300, 200, 400, 200)
|
||||||
.toFile(fixtures.path('output.extract.png'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(400, info.width);
|
assert.strictEqual(400, info.width);
|
||||||
assert.strictEqual(200, info.height);
|
assert.strictEqual(200, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,11 +35,11 @@ describe('Partial image extraction', function() {
|
|||||||
it('WebP', function(done) {
|
it('WebP', function(done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.extract(50, 100, 125, 200)
|
.extract(50, 100, 125, 200)
|
||||||
.toFile(fixtures.path('output.extract.webp'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(125, info.width);
|
assert.strictEqual(125, info.width);
|
||||||
assert.strictEqual(200, info.height);
|
assert.strictEqual(200, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -47,11 +47,12 @@ describe('Partial image extraction', function() {
|
|||||||
it('TIFF', function(done) {
|
it('TIFF', function(done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.extract(63, 34, 341, 529)
|
.extract(63, 34, 341, 529)
|
||||||
.toFile(fixtures.path('output.extract.tiff'), function(err, info) {
|
.jpeg()
|
||||||
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(341, info.width);
|
assert.strictEqual(341, info.width);
|
||||||
assert.strictEqual(529, info.height);
|
assert.strictEqual(529, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -59,11 +60,11 @@ describe('Partial image extraction', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract(10, 10, 10, 500, 500)
|
.extract(10, 10, 10, 500, 500)
|
||||||
.resize(100, 100)
|
.resize(100, 100)
|
||||||
.toFile(fixtures.path('output.extract.resize.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract-resize.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,11 +73,11 @@ describe('Partial image extraction', function() {
|
|||||||
.resize(500, 500)
|
.resize(500, 500)
|
||||||
.crop(sharp.gravity.north)
|
.crop(sharp.gravity.north)
|
||||||
.extract(10, 10, 100, 100)
|
.extract(10, 10, 100, 100)
|
||||||
.toFile(fixtures.path('output.resize.crop.extract.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('resize-crop-extract.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,11 +87,11 @@ describe('Partial image extraction', function() {
|
|||||||
.resize(500, 500)
|
.resize(500, 500)
|
||||||
.crop(sharp.gravity.north)
|
.crop(sharp.gravity.north)
|
||||||
.extract(10, 10, 100, 100)
|
.extract(10, 10, 100, 100)
|
||||||
.toFile(fixtures.path('output.extract.resize.crop.extract.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract-resize-crop-extract.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,11 +99,11 @@ describe('Partial image extraction', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract(10, 10, 100, 100)
|
.extract(10, 10, 100, 100)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.toFile(fixtures.path('output.extract.extract-then-rotate.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('extract-rotate.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -110,69 +111,44 @@ describe('Partial image extraction', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.extract(10, 10, 100, 100)
|
.extract(10, 10, 100, 100)
|
||||||
.toFile(fixtures.path('output.extract.rotate-then-extract.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('rotate-extract.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid parameters', function() {
|
describe('Invalid parameters', function() {
|
||||||
|
|
||||||
it('Undefined', function(done) {
|
it('Undefined', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).extract();
|
sharp(fixtures.inputJpg).extract();
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('String top', function(done) {
|
it('String top', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-integral left', function(done) {
|
it('Non-integral left', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Negative width - negative', function(done) {
|
it('Negative width - negative', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Null height', function(done) {
|
it('Null height', function() {
|
||||||
var isValid = true;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
||||||
} catch (err) {
|
});
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
assert.strictEqual(false, isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -37,12 +37,12 @@ describe('Rotation', function() {
|
|||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toFile(fixtures.path('output.exif.8.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,12 +50,12 @@ describe('Rotation', function() {
|
|||||||
sharp(fixtures.inputJpgWithExifMirroring)
|
sharp(fixtures.inputJpgWithExifMirroring)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toFile(fixtures.path('output.exif.5.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -85,26 +85,22 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate to an invalid angle, should fail', function(done) {
|
it('Rotate to an invalid angle, should fail', function() {
|
||||||
var fail = false;
|
assert.throws(function() {
|
||||||
try {
|
|
||||||
sharp(fixtures.inputJpg).rotate(1);
|
sharp(fixtures.inputJpg).rotate(1);
|
||||||
fail = true;
|
});
|
||||||
} catch (e) {}
|
|
||||||
assert(!fail);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flip - vertical', function(done) {
|
it('Flip - vertical', function(done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip()
|
.flip()
|
||||||
.toFile(fixtures.path('output.flip.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,12 +108,12 @@ describe('Rotation', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flop()
|
.flop()
|
||||||
.toFile(fixtures.path('output.flop.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -125,12 +121,12 @@ describe('Rotation', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flop()
|
.flop()
|
||||||
.toFile(fixtures.path('output.flip.flop.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.expected('flip-and-flop.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,12 +135,12 @@ describe('Rotation', function() {
|
|||||||
.resize(320)
|
.resize(320)
|
||||||
.flip(false)
|
.flip(false)
|
||||||
.flop(false)
|
.flop(false)
|
||||||
.toFile(fixtures.path('output.flip.flop.nope.jpg'), function(err, info) {
|
.toBuffer(function(err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
done();
|
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|