mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Update tests to meet semistandard code standards
Switch to const/let instead of var
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
|
||||
describe('Alpha transparency', function() {
|
||||
|
||||
it('Flatten to black', function(done) {
|
||||
describe('Alpha transparency', function () {
|
||||
it('Flatten to black', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten()
|
||||
.resize(400, 300)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@@ -18,12 +17,12 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten to RGB orange', function(done) {
|
||||
it('Flatten to RGB orange', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten()
|
||||
.background({r: 255, g: 102, b: 0})
|
||||
.resize(400, 300)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@@ -31,12 +30,12 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten to CSS/hex orange', function(done) {
|
||||
it('Flatten to CSS/hex orange', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten()
|
||||
.background('#ff6600')
|
||||
.resize(400, 300)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@@ -44,12 +43,12 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten 16-bit PNG with transparency to orange', function(done) {
|
||||
var output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
it('Flatten 16-bit PNG with transparency to orange', function (done) {
|
||||
const output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.flatten()
|
||||
.background({r: 255, g: 102, b: 0})
|
||||
.toFile(output, function(err, info) {
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual(32, info.width);
|
||||
@@ -59,10 +58,10 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not flatten', function(done) {
|
||||
it('Do not flatten', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten(false)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@@ -70,11 +69,11 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Ignored for JPEG', function(done) {
|
||||
it('Ignored for JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.background('#ff0000')
|
||||
.flatten()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@@ -82,13 +81,13 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function(done) {
|
||||
var BASE_NAME = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||
var actual = fixtures.path('output.' + BASE_NAME);
|
||||
var expected = fixtures.expected(BASE_NAME);
|
||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
||||
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||
const actual = fixtures.path('output.' + base);
|
||||
const expected = fixtures.expected(base);
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.resize(2048, 1536)
|
||||
.toFile(actual, function(err) {
|
||||
.toFile(actual, function (err) {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
@@ -98,13 +97,13 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function(done) {
|
||||
var BASE_NAME = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||
var actual = fixtures.path('output.' + BASE_NAME);
|
||||
var expected = fixtures.expected(BASE_NAME);
|
||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
||||
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||
const actual = fixtures.path('output.' + base);
|
||||
const expected = fixtures.expected(base);
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.resize(1024, 768)
|
||||
.toFile(actual, function(err) {
|
||||
.toFile(actual, function (err) {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
@@ -113,5 +112,4 @@ describe('Alpha transparency', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
|
||||
describe('Bandbool per-channel boolean operations', function() {
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
|
||||
describe('Bandbool per-channel boolean operations', function () {
|
||||
[
|
||||
sharp.bool.and,
|
||||
sharp.bool.or,
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function(op) {
|
||||
it(op + ' operation', function(done) {
|
||||
.forEach(function (op) {
|
||||
it(op + ' operation', function (done) {
|
||||
sharp(fixtures.inputPngBooleanNoAlpha)
|
||||
.bandbool(op)
|
||||
.toColourspace('b-w')
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@@ -26,23 +25,24 @@ describe('Bandbool per-channel boolean operations', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('sRGB image retains 3 channels', function(done) {
|
||||
it('sRGB image retains 3 channels', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.bandbool('and')
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, info.channels);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid operation', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid operation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().bandbool('fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing operation', function() {
|
||||
assert.throws(function() {
|
||||
it('Missing operation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().bandbool();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Blur', function() {
|
||||
|
||||
it('specific radius 1', function(done) {
|
||||
describe('Blur', function () {
|
||||
it('specific radius 1', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(1)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -19,11 +19,12 @@ describe('Blur', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 10', function(done) {
|
||||
it('specific radius 10', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(10)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -31,11 +32,12 @@ describe('Blur', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 0.3', function(done) {
|
||||
it('specific radius 0.3', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(0.3)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -43,11 +45,12 @@ describe('Blur', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('mild blur', function(done) {
|
||||
it('mild blur', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -55,17 +58,18 @@ describe('Blur', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid radius', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid radius', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).blur(0.1);
|
||||
});
|
||||
});
|
||||
|
||||
it('blurred image is smaller than non-blurred', function(done) {
|
||||
it('blurred image is smaller than non-blurred', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(false)
|
||||
.toBuffer(function(err, notBlurred, info) {
|
||||
.toBuffer(function (err, notBlurred, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, notBlurred.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -73,7 +77,8 @@ describe('Blur', function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(true)
|
||||
.toBuffer(function(err, blurred, info) {
|
||||
.toBuffer(function (err, blurred, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, blurred.length > 0);
|
||||
assert.strictEqual(true, blurred.length < notBlurred.length);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -83,5 +88,4 @@ describe('Blur', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
|
||||
describe('Boolean operation between two images', function() {
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
|
||||
var inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||
describe('Boolean operation between two images', function () {
|
||||
const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||
|
||||
[
|
||||
sharp.bool.and,
|
||||
sharp.bool.or,
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function(op) {
|
||||
|
||||
it(op + ' operation, file', function(done) {
|
||||
.forEach(function (op) {
|
||||
it(op + ' operation, file', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(fixtures.inputJpgBooleanTest, op)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -28,11 +27,11 @@ describe('Boolean operation between two images', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it(op + ' operation, buffer', function(done) {
|
||||
it(op + ' operation, buffer', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(inputJpgBooleanTestBuffer, op)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -40,15 +39,15 @@ describe('Boolean operation between two images', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it(op + ' operation, raw', function(done) {
|
||||
it(op + ' operation, raw', function (done) {
|
||||
sharp(fixtures.inputJpgBooleanTest)
|
||||
.raw()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(data, op, { raw: info })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -56,23 +55,22 @@ describe('Boolean operation between two images', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Invalid operation', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid operation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().boolean(fixtures.inputJpgBooleanTest, 'fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid operation, non-string', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid operation, non-string', function () {
|
||||
assert.throws(function () {
|
||||
sharp().boolean(fixtures.inputJpgBooleanTest, null);
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing input', function() {
|
||||
assert.throws(function() {
|
||||
it('Missing input', function () {
|
||||
assert.throws(function () {
|
||||
sharp().boolean();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var sharp = require('../../index');
|
||||
const sharp = require('../../index');
|
||||
|
||||
// Define SHARP_TEST_WITHOUT_CACHE environment variable to prevent use of libvips' cache
|
||||
|
||||
beforeEach(function() {
|
||||
sharp.cache(process.env.SHARP_TEST_WITHOUT_CACHE ? false : true);
|
||||
beforeEach(function () {
|
||||
sharp.cache(!process.env.SHARP_TEST_WITHOUT_CACHE);
|
||||
});
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Clone', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
describe('Clone', function () {
|
||||
beforeEach(function () {
|
||||
sharp.cache(false);
|
||||
});
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sharp.cache(true);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to multiple Streams', function(done) {
|
||||
var finishEventsExpected = 2;
|
||||
it('Read from Stream and write to multiple Streams', function (done) {
|
||||
let finishEventsExpected = 2;
|
||||
// Output stream 1
|
||||
var output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||
var writable1 = fs.createWriteStream(output1);
|
||||
writable1.on('finish', function() {
|
||||
sharp(output1).toBuffer(function(err, data, info) {
|
||||
const output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||
const writable1 = fs.createWriteStream(output1);
|
||||
writable1.on('finish', function () {
|
||||
sharp(output1).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@@ -36,10 +35,10 @@ describe('Clone', function() {
|
||||
});
|
||||
});
|
||||
// Output stream 2
|
||||
var output2 = fixtures.path('output.multi-stream.2.jpg');
|
||||
var writable2 = fs.createWriteStream(output2);
|
||||
writable2.on('finish', function() {
|
||||
sharp(output2).toBuffer(function(err, data, info) {
|
||||
const output2 = fixtures.path('output.multi-stream.2.jpg');
|
||||
const writable2 = fs.createWriteStream(output2);
|
||||
writable2.on('finish', function () {
|
||||
sharp(output2).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@@ -54,12 +53,11 @@ describe('Clone', function() {
|
||||
});
|
||||
});
|
||||
// Create parent instance
|
||||
var rotator = sharp().rotate(90);
|
||||
const rotator = sharp().rotate(90);
|
||||
// Cloned instances with differing dimensions
|
||||
rotator.clone().resize(320, 240).pipe(writable1);
|
||||
rotator.clone().resize(100, 122).pipe(writable2);
|
||||
// Go
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Colour space conversion', function() {
|
||||
|
||||
it('To greyscale', function(done) {
|
||||
describe('Colour space conversion', function () {
|
||||
it('To greyscale', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale()
|
||||
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
||||
});
|
||||
|
||||
it('To greyscale with gamma correction', function(done) {
|
||||
it('To greyscale with gamma correction', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.gamma()
|
||||
@@ -22,19 +21,19 @@ describe('Colour space conversion', function() {
|
||||
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
||||
});
|
||||
|
||||
it('Not to greyscale', function(done) {
|
||||
it('Not to greyscale', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale(false)
|
||||
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
||||
});
|
||||
|
||||
it('Greyscale with single channel output', function(done) {
|
||||
it('Greyscale with single channel output', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale()
|
||||
.toColourspace('b-w')
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, info.channels);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -44,10 +43,10 @@ describe('Colour space conversion', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) {
|
||||
it('From 1-bit TIFF to sRGB WebP [slow]', function(done) {
|
||||
it('From 1-bit TIFF to sRGB WebP [slow]', function (done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@@ -56,10 +55,10 @@ describe('Colour space conversion', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('From CMYK to sRGB', function(done) {
|
||||
it('From CMYK to sRGB', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(320)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -68,12 +67,12 @@ describe('Colour space conversion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('From CMYK to sRGB with white background, not yellow', function(done) {
|
||||
it('From CMYK to sRGB with white background, not yellow', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(320, 240)
|
||||
.background('white')
|
||||
.embed()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -82,10 +81,10 @@ describe('Colour space conversion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('From profile-less CMYK to sRGB', function(done) {
|
||||
it('From profile-less CMYK to sRGB', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykNoProfile)
|
||||
.resize(320)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -93,8 +92,8 @@ describe('Colour space conversion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid input', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid input', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toColourspace(null);
|
||||
});
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Convolve', function() {
|
||||
|
||||
it('specific convolution kernel 1', function(done) {
|
||||
describe('Convolve', function () {
|
||||
it('specific convolution kernel 1', function (done) {
|
||||
sharp(fixtures.inputPngStripesV)
|
||||
.convolve({
|
||||
width: 3,
|
||||
@@ -15,10 +14,10 @@ describe('Convolve', function() {
|
||||
scale: 50,
|
||||
offset: 0,
|
||||
kernel: [ 10, 20, 10,
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
10, 20, 10 ]
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -27,7 +26,7 @@ describe('Convolve', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific convolution kernel 2', function(done) {
|
||||
it('specific convolution kernel 2', function (done) {
|
||||
sharp(fixtures.inputPngStripesH)
|
||||
.convolve({
|
||||
width: 3,
|
||||
@@ -36,7 +35,7 @@ describe('Convolve', function() {
|
||||
2, 0, 2,
|
||||
1, 0, 1 ]
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -45,7 +44,7 @@ describe('Convolve', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('horizontal Sobel operator', function(done) {
|
||||
it('horizontal Sobel operator', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.convolve({
|
||||
@@ -55,7 +54,7 @@ describe('Convolve', function() {
|
||||
-2, 0, 2,
|
||||
-1, 0, 1 ]
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -64,14 +63,14 @@ describe('Convolve', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid kernel specification', function() {
|
||||
it('missing', function() {
|
||||
assert.throws(function() {
|
||||
describe('invalid kernel specification', function () {
|
||||
it('missing', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).convolve({});
|
||||
});
|
||||
});
|
||||
it('incorrect data format', function() {
|
||||
assert.throws(function() {
|
||||
it('incorrect data format', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).convolve({
|
||||
width: 3,
|
||||
height: 3,
|
||||
@@ -79,8 +78,8 @@ describe('Convolve', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('incorrect dimensions', function() {
|
||||
assert.throws(function() {
|
||||
it('incorrect dimensions', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).convolve({
|
||||
width: 3,
|
||||
height: 4,
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
var cpplint = require('node-cpplint/lib/');
|
||||
|
||||
describe('cpplint', function() {
|
||||
const cpplint = require('node-cpplint/lib/');
|
||||
|
||||
describe('cpplint', function () {
|
||||
// Ignore cpplint failures, possibly newline-related, on Windows
|
||||
if (process.platform !== 'win32') {
|
||||
// List C++ source files
|
||||
fs.readdirSync(path.join(__dirname, '..', '..', 'src')).filter(function(source) {
|
||||
fs.readdirSync(path.join(__dirname, '..', '..', 'src')).filter(function (source) {
|
||||
return source !== 'libvips';
|
||||
}).forEach(function(source) {
|
||||
var file = path.join('src', source);
|
||||
it(file, function(done) {
|
||||
}).forEach(function (source) {
|
||||
const file = path.join('src', source);
|
||||
it(file, function (done) {
|
||||
// Lint each source file
|
||||
cpplint({
|
||||
files: [file],
|
||||
@@ -34,18 +33,16 @@ describe('cpplint', function() {
|
||||
indentation_namespace: false
|
||||
}
|
||||
}
|
||||
}, function(err, report) {
|
||||
}, function (err, report) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
var expected = {};
|
||||
const expected = {};
|
||||
expected[file] = [];
|
||||
assert.deepEqual(expected, report);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
describe('Crop', function() {
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Crop', function () {
|
||||
[
|
||||
{
|
||||
name: 'North',
|
||||
@@ -113,12 +112,12 @@ describe('Crop', function() {
|
||||
gravity: sharp.gravity.northwest,
|
||||
fixture: 'gravity-west.jpg'
|
||||
}
|
||||
].forEach(function(settings) {
|
||||
it(settings.name + ' gravity', function(done) {
|
||||
].forEach(function (settings) {
|
||||
it(settings.name + ' gravity', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(settings.width, settings.height)
|
||||
.crop(settings.gravity)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(settings.width, info.width);
|
||||
assert.strictEqual(settings.height, info.height);
|
||||
@@ -127,11 +126,11 @@ describe('Crop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Allows specifying the gravity as a string', function(done) {
|
||||
it('Allows specifying the gravity as a string', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80, 320)
|
||||
.crop('east')
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(80, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
@@ -139,34 +138,33 @@ describe('Crop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid values fail', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid values fail', function () {
|
||||
assert.throws(function () {
|
||||
sharp().crop(9);
|
||||
});
|
||||
assert.throws(function() {
|
||||
assert.throws(function () {
|
||||
sharp().crop(1.1);
|
||||
});
|
||||
assert.throws(function() {
|
||||
assert.throws(function () {
|
||||
sharp().crop(-1);
|
||||
});
|
||||
assert.throws(function() {
|
||||
assert.throws(function () {
|
||||
sharp().crop('zoinks');
|
||||
});
|
||||
});
|
||||
|
||||
it('Uses default value when none specified', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
it('Uses default value when none specified', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().crop();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Entropy-based strategy', function() {
|
||||
|
||||
it('JPEG', function(done) {
|
||||
describe('Entropy-based strategy', function () {
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(80, 320)
|
||||
.crop(sharp.strategy.entropy)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@@ -178,11 +176,11 @@ describe('Crop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function(done) {
|
||||
it('PNG', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80)
|
||||
.crop(sharp.strategy.entropy)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@@ -193,16 +191,14 @@ describe('Crop', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Attention strategy', function() {
|
||||
|
||||
it('JPEG', function(done) {
|
||||
describe('Attention strategy', function () {
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(80, 320)
|
||||
.crop(sharp.strategy.attention)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@@ -214,11 +210,11 @@ describe('Crop', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function(done) {
|
||||
it('PNG', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80)
|
||||
.crop(sharp.strategy.attention)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@@ -229,6 +225,5 @@ describe('Crop', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Embed', function() {
|
||||
|
||||
it('JPEG within PNG, no alpha channel', function(done) {
|
||||
describe('Embed', function () {
|
||||
it('JPEG within PNG, no alpha channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.embed()
|
||||
.resize(320, 240)
|
||||
.png()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -24,13 +23,13 @@ describe('Embed', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.buffer) {
|
||||
it('JPEG within WebP, to include alpha channel', function(done) {
|
||||
it('JPEG within WebP, to include alpha channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.embed()
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@@ -42,11 +41,11 @@ describe('Embed', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('PNG with alpha channel', function(done) {
|
||||
it('PNG with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(50, 50)
|
||||
.embed()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -57,11 +56,11 @@ describe('Embed', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit PNG with alpha channel', function(done) {
|
||||
it('16-bit PNG with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 16)
|
||||
.embed()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -72,12 +71,12 @@ describe('Embed', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit PNG with alpha channel onto RGBA', function(done) {
|
||||
it('16-bit PNG with alpha channel onto RGBA', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 16)
|
||||
.embed()
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -88,12 +87,12 @@ describe('Embed', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with 2 channels', function(done) {
|
||||
it('PNG with 2 channels', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(32, 16)
|
||||
.embed()
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -104,11 +103,11 @@ describe('Embed', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Enlarge and embed', function(done) {
|
||||
it('Enlarge and embed', function (done) {
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.embed()
|
||||
.resize(320, 240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -118,5 +117,4 @@ describe('Embed', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Extend', function () {
|
||||
|
||||
it('extend all sides equally with RGB', function(done) {
|
||||
it('extend all sides equally with RGB', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(120)
|
||||
.background({r: 255, g: 0, b: 0})
|
||||
.extend(10)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(140, info.width);
|
||||
assert.strictEqual(118, info.height);
|
||||
@@ -20,12 +19,12 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('extend sides unequally with RGBA', function(done) {
|
||||
it('extend sides unequally with RGBA', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(120)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.extend({top: 50, bottom: 0, left: 10, right: 35})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(165, info.width);
|
||||
assert.strictEqual(170, info.height);
|
||||
@@ -33,32 +32,32 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('missing parameter fails', function() {
|
||||
assert.throws(function() {
|
||||
it('missing parameter fails', function () {
|
||||
assert.throws(function () {
|
||||
sharp().extend();
|
||||
});
|
||||
});
|
||||
it('negative fails', function() {
|
||||
assert.throws(function() {
|
||||
it('negative fails', function () {
|
||||
assert.throws(function () {
|
||||
sharp().extend(-1);
|
||||
});
|
||||
});
|
||||
it('partial object fails', function() {
|
||||
assert.throws(function() {
|
||||
it('partial object fails', function () {
|
||||
assert.throws(function () {
|
||||
sharp().extend({top: 1});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add alpha channel before extending with a transparent Background', function( done ){
|
||||
it('should add alpha channel before extending with a transparent Background', function (done) {
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.toFormat( sharp.format.png )
|
||||
.toFormat(sharp.format.png)
|
||||
.extend({top: 0, bottom: 10, left: 0, right: 10})
|
||||
.toBuffer( function(err, data, info){
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(610, info.width);
|
||||
assert.strictEqual(460, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Partial image extraction', function() {
|
||||
|
||||
it('JPEG', function(done) {
|
||||
describe('Partial image extraction', function () {
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(20, info.width);
|
||||
assert.strictEqual(20, info.height);
|
||||
@@ -18,10 +17,10 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function(done) {
|
||||
it('PNG', function (done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@@ -30,10 +29,10 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.file) {
|
||||
it('WebP', function(done) {
|
||||
it('WebP', function (done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(125, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@@ -43,11 +42,11 @@ describe('Partial image extraction', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.tiff.output.file) {
|
||||
it('TIFF', function(done) {
|
||||
it('TIFF', function (done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
||||
.jpeg()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(341, info.width);
|
||||
assert.strictEqual(529, info.height);
|
||||
@@ -56,11 +55,11 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('Before resize', function(done) {
|
||||
it('Before resize', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
||||
.resize(100, 100)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@@ -68,12 +67,12 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('After resize and crop', function(done) {
|
||||
it('After resize and crop', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(500, 500)
|
||||
.crop(sharp.gravity.north)
|
||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@@ -81,13 +80,13 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Before and after resize and crop', function(done) {
|
||||
it('Before and after resize and crop', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
||||
.resize(500, 500)
|
||||
.crop(sharp.gravity.north)
|
||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@@ -95,11 +94,11 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Extract then rotate', function(done) {
|
||||
it('Extract then rotate', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||
.rotate(90)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(280, info.width);
|
||||
assert.strictEqual(380, info.height);
|
||||
@@ -107,11 +106,11 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate then extract', function(done) {
|
||||
it('Rotate then extract', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.rotate(90)
|
||||
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(280, info.width);
|
||||
assert.strictEqual(380, info.height);
|
||||
@@ -119,69 +118,69 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid parameters', function() {
|
||||
describe('Invalid parameters', function () {
|
||||
describe('using the legacy extract(top,left,width,height) syntax', function () {
|
||||
it('String top', function() {
|
||||
assert.throws(function() {
|
||||
it('String top', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-integral left', function() {
|
||||
assert.throws(function() {
|
||||
it('Non-integral left', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Negative width - negative', function() {
|
||||
assert.throws(function() {
|
||||
it('Negative width - negative', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Null height', function() {
|
||||
assert.throws(function() {
|
||||
it('Null height', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Undefined', function() {
|
||||
assert.throws(function() {
|
||||
it('Undefined', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract();
|
||||
});
|
||||
});
|
||||
|
||||
it('String top', function() {
|
||||
assert.throws(function() {
|
||||
it('String top', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 'spoons', width: 10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-integral left', function() {
|
||||
assert.throws(function() {
|
||||
it('Non-integral left', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10.2, top: 10, width: 10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Negative width - negative', function() {
|
||||
assert.throws(function() {
|
||||
it('Negative width - negative', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: -10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Null height', function() {
|
||||
assert.throws(function() {
|
||||
it('Null height', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: 10, height: null });
|
||||
});
|
||||
});
|
||||
|
||||
it('Bad image area', function(done) {
|
||||
it('Bad image area', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
||||
.toBuffer(function(err) {
|
||||
.toBuffer(function (err) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual(err.message, "extract_area: bad extract area\n");
|
||||
assert.strictEqual(err.message, 'extract_area: bad extract area\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Image channel extraction', function() {
|
||||
|
||||
it('Red channel', function(done) {
|
||||
describe('Image channel extraction', function () {
|
||||
it('Red channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('red')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -19,11 +18,11 @@ describe('Image channel extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Green channel', function(done) {
|
||||
it('Green channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('green')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -31,11 +30,11 @@ describe('Image channel extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel', function(done) {
|
||||
it('Blue channel', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('blue')
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -43,11 +42,11 @@ describe('Image channel extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel by number', function(done) {
|
||||
it('Blue channel by number', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(2)
|
||||
.resize(320,240)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -55,27 +54,26 @@ describe('Image channel extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid channel number', function() {
|
||||
assert.throws(function() {
|
||||
it('Invalid channel number', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('No arguments', function() {
|
||||
assert.throws(function() {
|
||||
it('No arguments', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel();
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-existant channel', function(done) {
|
||||
it('Non-existant channel', function (done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.extractChannel(1)
|
||||
.toBuffer(function(err) {
|
||||
.toBuffer(function (err) {
|
||||
assert(err instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Test fixtures', function() {
|
||||
describe('assertMaxColourDistance', function() {
|
||||
it('should throw an Error when images have a different number of channels', function() {
|
||||
assert.throws(function() {
|
||||
describe('Test fixtures', function () {
|
||||
describe('assertMaxColourDistance', function () {
|
||||
it('should throw an Error when images have a different number of channels', function () {
|
||||
assert.throws(function () {
|
||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer1, fixtures.inputJpg);
|
||||
});
|
||||
});
|
||||
it('should throw an Error when images have different dimensions', function() {
|
||||
assert.throws(function() {
|
||||
it('should throw an Error when images have different dimensions', function () {
|
||||
assert.throws(function () {
|
||||
fixtures.assertMaxColourDistance(fixtures.inputJpg, fixtures.inputJpgWithExif);
|
||||
});
|
||||
});
|
||||
it('should accept a zero threshold when comparing an image to itself', function() {
|
||||
var image = fixtures.inputPngOverlayLayer0;
|
||||
it('should accept a zero threshold when comparing an image to itself', function () {
|
||||
const image = fixtures.inputPngOverlayLayer0;
|
||||
fixtures.assertMaxColourDistance(image, image, 0);
|
||||
});
|
||||
it('should accept a numeric threshold for two different images', function() {
|
||||
it('should accept a numeric threshold for two different images', function () {
|
||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer0, fixtures.inputPngOverlayLayer1, 100);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Gamma correction', function() {
|
||||
|
||||
it('value of 0.0 (disabled)', function(done) {
|
||||
describe('Gamma correction', function () {
|
||||
it('value of 0.0 (disabled)', function (done) {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@@ -18,11 +18,12 @@ describe('Gamma correction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('value of 2.2 (default)', function(done) {
|
||||
it('value of 2.2 (default)', function (done) {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.gamma()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@@ -30,11 +31,12 @@ describe('Gamma correction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('value of 3.0', function(done) {
|
||||
it('value of 3.0', function (done) {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.gamma(3)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@@ -42,21 +44,21 @@ describe('Gamma correction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('alpha transparency', function(done) {
|
||||
it('alpha transparency', function (done) {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(320)
|
||||
.gamma()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, { threshold: 11 }, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid value', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid value', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Interpolators and kernels', function() {
|
||||
|
||||
describe('Reducers', function() {
|
||||
describe('Interpolators and kernels', function () {
|
||||
describe('Reducers', function () {
|
||||
[
|
||||
sharp.kernel.cubic,
|
||||
sharp.kernel.lanczos2,
|
||||
sharp.kernel.lanczos3
|
||||
].forEach(function(kernel) {
|
||||
it(kernel, function(done) {
|
||||
].forEach(function (kernel) {
|
||||
it(kernel, function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, null, { kernel: kernel })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -26,7 +25,7 @@ describe('Interpolators and kernels', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Enlargers', function() {
|
||||
describe('Enlargers', function () {
|
||||
[
|
||||
sharp.interpolator.nearest,
|
||||
sharp.interpolator.bilinear,
|
||||
@@ -34,11 +33,11 @@ describe('Interpolators and kernels', function() {
|
||||
sharp.interpolator.nohalo,
|
||||
sharp.interpolator.locallyBoundedBicubic,
|
||||
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
||||
].forEach(function(interpolator) {
|
||||
it(interpolator, function(done) {
|
||||
].forEach(function (interpolator) {
|
||||
it(interpolator, function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, null, { interpolator: interpolator })
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -48,16 +47,15 @@ describe('Interpolators and kernels', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown kernel throws', function() {
|
||||
assert.throws(function() {
|
||||
it('unknown kernel throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().resize(null, null, { kernel: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown interpolator throws', function() {
|
||||
assert.throws(function() {
|
||||
it('unknown interpolator throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().resize(null, null, { interpolator: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
484
test/unit/io.js
484
test/unit/io.js
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var exifReader = require('exif-reader');
|
||||
var icc = require('icc');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const exifReader = require('exif-reader');
|
||||
const icc = require('icc');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Image metadata', function() {
|
||||
|
||||
it('JPEG', function(done) {
|
||||
sharp(fixtures.inputJpg).metadata(function(err, metadata) {
|
||||
describe('Image metadata', function () {
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@@ -28,8 +27,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG with EXIF/ICC', function(done) {
|
||||
sharp(fixtures.inputJpgWithExif).metadata(function(err, metadata) {
|
||||
it('JPEG with EXIF/ICC', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(450, metadata.width);
|
||||
@@ -43,14 +42,14 @@ describe('Image metadata', function() {
|
||||
// EXIF
|
||||
assert.strictEqual('object', typeof metadata.exif);
|
||||
assert.strictEqual(true, metadata.exif instanceof Buffer);
|
||||
var exif = exifReader(metadata.exif);
|
||||
const exif = exifReader(metadata.exif);
|
||||
assert.strictEqual('object', typeof exif);
|
||||
assert.strictEqual('object', typeof exif.image);
|
||||
assert.strictEqual('number', typeof exif.image.XResolution);
|
||||
// ICC
|
||||
assert.strictEqual('object', typeof metadata.icc);
|
||||
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
||||
var profile = icc.parse(metadata.icc);
|
||||
const profile = icc.parse(metadata.icc);
|
||||
assert.strictEqual('object', typeof profile);
|
||||
assert.strictEqual('Generic RGB Profile', profile.description);
|
||||
done();
|
||||
@@ -58,8 +57,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.tiff.input.file) {
|
||||
it('TIFF', function(done) {
|
||||
sharp(fixtures.inputTiff).metadata(function(err, metadata) {
|
||||
it('TIFF', function (done) {
|
||||
sharp(fixtures.inputTiff).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', metadata.format);
|
||||
assert.strictEqual(2464, metadata.width);
|
||||
@@ -77,8 +76,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('PNG', function(done) {
|
||||
sharp(fixtures.inputPng).metadata(function(err, metadata) {
|
||||
it('PNG', function (done) {
|
||||
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual(2809, metadata.width);
|
||||
@@ -95,8 +94,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Transparent PNG', function(done) {
|
||||
sharp(fixtures.inputPngWithTransparency).metadata(function(err, metadata) {
|
||||
it('Transparent PNG', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual(2048, metadata.width);
|
||||
@@ -114,8 +113,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.webp.input.file) {
|
||||
it('WebP', function(done) {
|
||||
sharp(fixtures.inputWebP).metadata(function(err, metadata) {
|
||||
it('WebP', function (done) {
|
||||
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual(1024, metadata.width);
|
||||
@@ -134,8 +133,8 @@ describe('Image metadata', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.gif.input.file) {
|
||||
it('GIF via giflib', function(done) {
|
||||
sharp(fixtures.inputGif).metadata(function(err, metadata) {
|
||||
it('GIF via giflib', function (done) {
|
||||
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('gif', metadata.format);
|
||||
assert.strictEqual(800, metadata.width);
|
||||
@@ -150,8 +149,8 @@ describe('Image metadata', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('GIF grey+alpha via giflib', function(done) {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function(err, metadata) {
|
||||
it('GIF grey+alpha via giflib', function (done) {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('gif', metadata.format);
|
||||
assert.strictEqual(2, metadata.width);
|
||||
@@ -169,8 +168,8 @@ describe('Image metadata', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.openslide.input.file) {
|
||||
it('Aperio SVS via openslide', function(done) {
|
||||
sharp(fixtures.inputSvs).metadata(function(err, metadata) {
|
||||
it('Aperio SVS via openslide', function (done) {
|
||||
sharp(fixtures.inputSvs).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('openslide', metadata.format);
|
||||
assert.strictEqual(2220, metadata.width);
|
||||
@@ -188,8 +187,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('File in, Promise out', function(done) {
|
||||
sharp(fixtures.inputJpg).metadata().then(function(metadata) {
|
||||
it('File in, Promise out', function (done) {
|
||||
sharp(fixtures.inputJpg).metadata().then(function (metadata) {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
assert.strictEqual(2225, metadata.height);
|
||||
@@ -205,8 +204,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-existent file in, Promise out', function(done) {
|
||||
sharp('fail').metadata().then(function(metadata) {
|
||||
it('Non-existent file in, Promise out', function (done) {
|
||||
sharp('fail').metadata().then(function (metadata) {
|
||||
throw new Error('Non-existent file');
|
||||
}, function (err) {
|
||||
assert.ok(!!err);
|
||||
@@ -214,10 +213,10 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Stream in, Promise out', function(done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp();
|
||||
pipeline.metadata().then(function(metadata) {
|
||||
it('Stream in, Promise out', function (done) {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp();
|
||||
pipeline.metadata().then(function (metadata) {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
assert.strictEqual(2225, metadata.height);
|
||||
@@ -230,15 +229,15 @@ describe('Image metadata', function() {
|
||||
assert.strictEqual('undefined', typeof metadata.exif);
|
||||
assert.strictEqual('undefined', typeof metadata.icc);
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
}).catch(function (err) {
|
||||
throw err;
|
||||
});
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Stream', function(done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp().metadata(function(err, metadata) {
|
||||
it('Stream', function (done) {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@@ -256,9 +255,9 @@ describe('Image metadata', function() {
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Resize to half width using metadata', function(done) {
|
||||
var image = sharp(fixtures.inputJpg);
|
||||
image.metadata(function(err, metadata) {
|
||||
it('Resize to half width using metadata', function (done) {
|
||||
const image = sharp(fixtures.inputJpg);
|
||||
image.metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@@ -271,7 +270,7 @@ describe('Image metadata', function() {
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
assert.strictEqual('undefined', typeof metadata.exif);
|
||||
assert.strictEqual('undefined', typeof metadata.icc);
|
||||
image.resize(Math.floor(metadata.width / 2)).toBuffer(function(err, data, info) {
|
||||
image.resize(Math.floor(metadata.width / 2)).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(1362, info.width);
|
||||
@@ -281,27 +280,27 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Keep EXIF metadata and add sRGB profile after a resize', function(done) {
|
||||
it('Keep EXIF metadata and add sRGB profile after a resize', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320, 240)
|
||||
.withMetadata()
|
||||
.toBuffer(function(err, buffer) {
|
||||
.toBuffer(function (err, buffer) {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function(err, metadata) {
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, metadata.hasProfile);
|
||||
assert.strictEqual(8, metadata.orientation);
|
||||
assert.strictEqual('object', typeof metadata.exif);
|
||||
assert.strictEqual(true, metadata.exif instanceof Buffer);
|
||||
// EXIF
|
||||
var exif = exifReader(metadata.exif);
|
||||
const exif = exifReader(metadata.exif);
|
||||
assert.strictEqual('object', typeof exif);
|
||||
assert.strictEqual('object', typeof exif.image);
|
||||
assert.strictEqual('number', typeof exif.image.XResolution);
|
||||
// ICC
|
||||
assert.strictEqual('object', typeof metadata.icc);
|
||||
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
||||
var profile = icc.parse(metadata.icc);
|
||||
const profile = icc.parse(metadata.icc);
|
||||
assert.strictEqual('object', typeof profile);
|
||||
assert.strictEqual('RGB', profile.colorSpace);
|
||||
assert.strictEqual('Perceptual', profile.intent);
|
||||
@@ -311,13 +310,13 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Remove EXIF metadata after a resize', function(done) {
|
||||
it('Remove EXIF metadata after a resize', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320, 240)
|
||||
.withMetadata(false)
|
||||
.toBuffer(function(err, buffer) {
|
||||
.toBuffer(function (err, buffer) {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function(err, metadata) {
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
@@ -328,12 +327,12 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Remove metadata from PNG output', function(done) {
|
||||
it('Remove metadata from PNG output', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.png()
|
||||
.toBuffer(function(err, buffer) {
|
||||
.toBuffer(function (err, buffer) {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function(err, metadata) {
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
@@ -344,30 +343,30 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully', function(done) {
|
||||
it('File input with corrupt header fails gracefully', function (done) {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.metadata(function(err) {
|
||||
.metadata(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Buffer input with corrupt header fails gracefully', function(done) {
|
||||
it('Buffer input with corrupt header fails gracefully', function (done) {
|
||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||
.metadata(function(err) {
|
||||
.metadata(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid withMetadata parameters', function() {
|
||||
it('String orientation', function() {
|
||||
assert.throws(function() {
|
||||
describe('Invalid withMetadata parameters', function () {
|
||||
it('String orientation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().withMetadata({orientation: 'zoinks'});
|
||||
});
|
||||
});
|
||||
it('Negative orientation', function() {
|
||||
assert.throws(function() {
|
||||
it('Negative orientation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().withMetadata({orientation: -1});
|
||||
});
|
||||
});
|
||||
@@ -376,8 +375,8 @@ describe('Image metadata', function() {
|
||||
sharp().withMetadata({ orientation: 0 });
|
||||
});
|
||||
});
|
||||
it('Too large orientation', function() {
|
||||
assert.throws(function() {
|
||||
it('Too large orientation', function () {
|
||||
assert.throws(function () {
|
||||
sharp().withMetadata({orientation: 9});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,105 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Negate', function() {
|
||||
it('negate (jpeg)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
describe('Negate', function () {
|
||||
it('negate (jpeg)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png)', function(done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.png'), data, done);
|
||||
});
|
||||
});
|
||||
it('negate (png)', function (done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png, trans)', function(done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done);
|
||||
});
|
||||
});
|
||||
it('negate (png, trans)', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png, alpha)', function(done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done);
|
||||
});
|
||||
});
|
||||
it('negate (png, alpha)', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.file) {
|
||||
it('negate (webp)', function(done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done);
|
||||
});
|
||||
});
|
||||
it('negate (webp)', function (done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (webp, trans)', function(done) {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
it('negate (webp, trans)', function (done) {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (true)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate(true)
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
it('negate (true)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate(true)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (false)', function(done) {
|
||||
var output = fixtures.path('output.unmodified-by-negate.png');
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.negate(false)
|
||||
.toFile(output, function(err, info) {
|
||||
if (err) done(err);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('negate (false)', function (done) {
|
||||
const output = fixtures.path('output.unmodified-by-negate.png');
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.negate(false)
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
var assertNormalized = function(data) {
|
||||
var min = 255;
|
||||
var max = 0;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
const assertNormalized = function (data) {
|
||||
let min = 255;
|
||||
let max = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
@@ -17,12 +17,11 @@ var assertNormalized = function(data) {
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
|
||||
it('uses the same prototype for both spellings', function() {
|
||||
it('uses the same prototype for both spellings', function () {
|
||||
assert.strictEqual(sharp.prototype.normalize, sharp.prototype.normalise);
|
||||
});
|
||||
|
||||
it('spreads rgb image values between 0 and 255', function(done) {
|
||||
it('spreads rgb image values between 0 and 255', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalize()
|
||||
.raw()
|
||||
@@ -33,7 +32,7 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('spreads grayscaled image values between 0 and 255', function(done) {
|
||||
it('spreads grayscaled image values between 0 and 255', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.gamma()
|
||||
.greyscale()
|
||||
@@ -46,7 +45,7 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('stretches greyscale images with alpha channel', function(done) {
|
||||
it('stretches greyscale images with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.raw()
|
||||
@@ -57,12 +56,12 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps an existing alpha channel', function(done) {
|
||||
it('keeps an existing alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
@@ -72,12 +71,12 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the alpha channel of greyscale images intact', function(done) {
|
||||
it('keeps the alpha channel of greyscale images intact', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
@@ -87,18 +86,18 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not alter images with only one color', function(done) {
|
||||
var output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
it('does not alter images with only one color', function (done) {
|
||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toFile(output, function(err, info) {
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) done(err);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('works with 16-bit RGBA images', function(done) {
|
||||
it('works with 16-bit RGBA images', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.normalize()
|
||||
.raw()
|
||||
@@ -108,5 +107,4 @@ describe('Normalization', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
|
||||
// Helpers
|
||||
var getPaths = function(baseName, extension) {
|
||||
const getPaths = function (baseName, extension) {
|
||||
if (typeof extension === 'undefined') {
|
||||
extension = 'png';
|
||||
}
|
||||
return {
|
||||
actual: fixtures.path('output.' + baseName + '.' + extension),
|
||||
expected: fixtures.expected(baseName + '.' + extension),
|
||||
expected: fixtures.expected(baseName + '.' + extension)
|
||||
};
|
||||
};
|
||||
|
||||
// Test
|
||||
describe('Overlays', function() {
|
||||
it('Overlay transparent PNG file on solid background', function(done) {
|
||||
var paths = getPaths('alpha-layer-01');
|
||||
describe('Overlays', function () {
|
||||
it('Overlay transparent PNG file on solid background', function (done) {
|
||||
const paths = getPaths('alpha-layer-01');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
@@ -30,8 +31,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay transparent PNG Buffer on solid background', function(done) {
|
||||
var paths = getPaths('alpha-layer-01');
|
||||
it('Overlay transparent PNG Buffer on solid background', function (done) {
|
||||
const paths = getPaths('alpha-layer-01');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fs.readFileSync(fixtures.inputPngOverlayLayer1))
|
||||
@@ -42,8 +43,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay low-alpha transparent PNG on solid background', function(done) {
|
||||
var paths = getPaths('alpha-layer-01-low-alpha');
|
||||
it('Overlay low-alpha transparent PNG on solid background', function (done) {
|
||||
const paths = getPaths('alpha-layer-01-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
@@ -54,8 +55,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite three transparent PNGs into one', function(done) {
|
||||
var paths = getPaths('alpha-layer-012');
|
||||
it('Composite three transparent PNGs into one', function (done) {
|
||||
const paths = getPaths('alpha-layer-012');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
@@ -71,8 +72,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite two transparent PNGs into one', function(done) {
|
||||
var paths = getPaths('alpha-layer-12');
|
||||
it('Composite two transparent PNGs into one', function (done) {
|
||||
const paths = getPaths('alpha-layer-12');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer2)
|
||||
@@ -83,8 +84,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite two low-alpha transparent PNGs into one', function(done) {
|
||||
var paths = getPaths('alpha-layer-12-low-alpha');
|
||||
it('Composite two low-alpha transparent PNGs into one', function (done) {
|
||||
const paths = getPaths('alpha-layer-12-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer2LowAlpha)
|
||||
@@ -95,8 +96,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite three low-alpha transparent PNGs into one', function(done) {
|
||||
var paths = getPaths('alpha-layer-012-low-alpha');
|
||||
it('Composite three low-alpha transparent PNGs into one', function (done) {
|
||||
const paths = getPaths('alpha-layer-012-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
@@ -113,26 +114,26 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite rgb+alpha PNG onto JPEG', function(done) {
|
||||
var paths = getPaths('overlay-jpeg-with-rgb', 'jpg');
|
||||
it('Composite rgb+alpha PNG onto JPEG', function (done) {
|
||||
const paths = getPaths('overlay-jpeg-with-rgb', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(2048, 1536)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
.toFile(paths.actual, function(error, info) {
|
||||
.toFile(paths.actual, function (error, info) {
|
||||
if (error) return done(error);
|
||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite greyscale+alpha PNG onto JPEG', function(done) {
|
||||
var paths = getPaths('overlay-jpeg-with-greyscale', 'jpg');
|
||||
it('Composite greyscale+alpha PNG onto JPEG', function (done) {
|
||||
const paths = getPaths('overlay-jpeg-with-greyscale', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400, 300)
|
||||
.overlayWith(fixtures.inputPngWithGreyAlpha)
|
||||
.toFile(paths.actual, function(error, info) {
|
||||
.toFile(paths.actual, function (error, info) {
|
||||
if (error) return done(error);
|
||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||
done();
|
||||
@@ -140,13 +141,13 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.webp.input.file) {
|
||||
it('Composite WebP onto JPEG', function(done) {
|
||||
var paths = getPaths('overlay-jpeg-with-webp', 'jpg');
|
||||
it('Composite WebP onto JPEG', function (done) {
|
||||
const paths = getPaths('overlay-jpeg-with-webp', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(300, 300)
|
||||
.overlayWith(fixtures.inputWebPWithTransparency)
|
||||
.toFile(paths.actual, function(error, info) {
|
||||
.toFile(paths.actual, function (error, info) {
|
||||
if (error) return done(error);
|
||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||
done();
|
||||
@@ -154,48 +155,48 @@ describe('Overlays', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('Composite JPEG onto PNG', function(done) {
|
||||
it('Composite JPEG onto PNG', function (done) {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
||||
.toBuffer(function(error) {
|
||||
.toBuffer(function (error) {
|
||||
if (error) return done(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite opaque JPEG onto JPEG', function(done) {
|
||||
it('Composite opaque JPEG onto JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
||||
.toBuffer(function(error) {
|
||||
.toBuffer(function (error) {
|
||||
if (error) return done(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when overlay is larger', function(done) {
|
||||
it('Fail when overlay is larger', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
.toBuffer(function(error) {
|
||||
.toBuffer(function (error) {
|
||||
assert.strictEqual(true, error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail with empty String parameter', function() {
|
||||
assert.throws(function() {
|
||||
it('Fail with empty String parameter', function () {
|
||||
assert.throws(function () {
|
||||
sharp().overlayWith('');
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail with non-String parameter', function() {
|
||||
assert.throws(function() {
|
||||
it('Fail with non-String parameter', function () {
|
||||
assert.throws(function () {
|
||||
sharp().overlayWith(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail with unsupported gravity', function() {
|
||||
assert.throws(function() {
|
||||
it('Fail with unsupported gravity', function () {
|
||||
assert.throws(function () {
|
||||
sharp()
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1, {
|
||||
gravity: 9
|
||||
@@ -203,22 +204,22 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Empty options', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
it('Empty options', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().overlayWith(fixtures.inputPngOverlayLayer1, {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Overlay with numeric gravity', function() {
|
||||
Object.keys(sharp.gravity).forEach(function(gravity) {
|
||||
it(gravity, function(done) {
|
||||
var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
describe('Overlay with numeric gravity', function () {
|
||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||
it(gravity, function (done) {
|
||||
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
gravity: gravity
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -230,16 +231,16 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Overlay with string-based gravity', function() {
|
||||
Object.keys(sharp.gravity).forEach(function(gravity) {
|
||||
it(gravity, function(done) {
|
||||
var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
describe('Overlay with string-based gravity', function () {
|
||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||
it(gravity, function (done) {
|
||||
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
gravity: sharp.gravity[gravity]
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -251,17 +252,17 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Overlay with tile enabled and gravity', function() {
|
||||
Object.keys(sharp.gravity).forEach(function(gravity) {
|
||||
it(gravity, function(done) {
|
||||
var expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg');
|
||||
describe('Overlay with tile enabled and gravity', function () {
|
||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||
it(gravity, function (done) {
|
||||
const expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
tile: true,
|
||||
gravity: gravity
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -273,43 +274,41 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Overlay with top-left offsets", function() {
|
||||
it('Overlay with 10px top & 10px left offsets', function(done) {
|
||||
var expected = fixtures.expected('overlay-valid-offsets-10-10.jpg');
|
||||
describe('Overlay with top-left offsets', function () {
|
||||
it('Overlay with 10px top & 10px left offsets', function (done) {
|
||||
const expected = fixtures.expected('overlay-valid-offsets-10-10.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
top: 10,
|
||||
left: 10
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with 100px top & 300px left offsets', function(done) {
|
||||
var expected = fixtures.expected('overlay-valid-offsets-100-300.jpg');
|
||||
it('Overlay with 100px top & 300px left offsets', function (done) {
|
||||
const expected = fixtures.expected('overlay-valid-offsets-100-300.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
top: 100,
|
||||
left: 300
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with only top offset', function() {
|
||||
assert.throws(function() {
|
||||
it('Overlay with only top offset', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@@ -318,84 +317,81 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with only left offset', function() {
|
||||
assert.throws(function() {
|
||||
it('Overlay with only left offset', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
left: 1000
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with negative offsets', function() {
|
||||
assert.throws(function() {
|
||||
it('Overlay with negative offsets', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
top: -1000,
|
||||
left: -1000
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with 0 offset', function(done) {
|
||||
var expected = fixtures.expected('overlay-offset-0.jpg');
|
||||
it('Overlay with 0 offset', function (done) {
|
||||
const expected = fixtures.expected('overlay-offset-0.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
top: 0,
|
||||
left: 0
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with offset and gravity', function(done) {
|
||||
var expected = fixtures.expected('overlay-offset-with-gravity.jpg');
|
||||
it('Overlay with offset and gravity', function (done) {
|
||||
const expected = fixtures.expected('overlay-offset-with-gravity.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
left: 10,
|
||||
top: 10,
|
||||
gravity : 4
|
||||
|
||||
gravity: 4
|
||||
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with offset and gravity and tile', function(done) {
|
||||
var expected = fixtures.expected('overlay-offset-with-gravity-tile.jpg');
|
||||
it('Overlay with offset and gravity and tile', function (done) {
|
||||
const expected = fixtures.expected('overlay-offset-with-gravity-tile.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
left: 10,
|
||||
top: 10,
|
||||
gravity : 4,
|
||||
gravity: 4,
|
||||
tile: true
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with offset and tile', function(done) {
|
||||
var expected = fixtures.expected('overlay-offset-with-tile.jpg');
|
||||
it('Overlay with offset and tile', function (done) {
|
||||
const expected = fixtures.expected('overlay-offset-with-tile.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@@ -403,7 +399,7 @@ describe('Overlays', function() {
|
||||
top: 10,
|
||||
tile: true
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@@ -411,27 +407,27 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with invalid cutout option', function() {
|
||||
assert.throws(function() {
|
||||
it('Overlay with invalid cutout option', function () {
|
||||
assert.throws(function () {
|
||||
sharp().overlayWith('ignore', { cutout: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with invalid tile option', function() {
|
||||
assert.throws(function() {
|
||||
it('Overlay with invalid tile option', function () {
|
||||
assert.throws(function () {
|
||||
sharp().overlayWith('ignore', { tile: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with very large offset', function(done) {
|
||||
var expected = fixtures.expected('overlay-very-large-offset.jpg');
|
||||
it('Overlay with very large offset', function (done) {
|
||||
const expected = fixtures.expected('overlay-very-large-offset.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
left: 10000,
|
||||
top: 10000
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@@ -439,10 +435,10 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay 100x100 with 50x50 so bottom edges meet', function(done) {
|
||||
it('Overlay 100x100 with 50x50 so bottom edges meet', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(50, 50)
|
||||
.toBuffer(function(err, overlay) {
|
||||
.toBuffer(function (err, overlay) {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
.resize(100, 100)
|
||||
@@ -450,7 +446,7 @@ describe('Overlays', function() {
|
||||
top: 50,
|
||||
left: 40
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
@@ -461,15 +457,15 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('With tile enabled and image rotated 90 degrees', function(done) {
|
||||
var expected = fixtures.expected('overlay-tile-rotated90.jpg');
|
||||
it('With tile enabled and image rotated 90 degrees', function (done) {
|
||||
const expected = fixtures.expected('overlay-tile-rotated90.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
tile: true
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -479,8 +475,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('With tile enabled and image rotated 90 degrees and gravity northwest', function(done) {
|
||||
var expected = fixtures.expected('overlay-tile-rotated90-gravity-northwest.jpg');
|
||||
it('With tile enabled and image rotated 90 degrees and gravity northwest', function (done) {
|
||||
const expected = fixtures.expected('overlay-tile-rotated90-gravity-northwest.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@@ -488,7 +484,7 @@ describe('Overlays', function() {
|
||||
tile: true,
|
||||
gravity: 'northwest'
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -498,17 +494,17 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Overlay with cutout enabled and gravity', function() {
|
||||
Object.keys(sharp.gravity).forEach(function(gravity) {
|
||||
it(gravity, function(done) {
|
||||
var expected = fixtures.expected('overlay-cutout-gravity-' + gravity + '.jpg');
|
||||
describe('Overlay with cutout enabled and gravity', function () {
|
||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||
it(gravity, function (done) {
|
||||
const expected = fixtures.expected('overlay-cutout-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
cutout: true,
|
||||
gravity: gravity
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -520,15 +516,15 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('With cutout enabled and image rotated 90 degrees', function(done) {
|
||||
var expected = fixtures.expected('overlay-cutout-rotated90.jpg');
|
||||
it('With cutout enabled and image rotated 90 degrees', function (done) {
|
||||
const expected = fixtures.expected('overlay-cutout-rotated90.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
cutout: true
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -538,8 +534,8 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('With cutout enabled and image rotated 90 degrees and gravity northwest', function(done) {
|
||||
var expected = fixtures.expected('overlay-cutout-rotated90-gravity-northwest.jpg');
|
||||
it('With cutout enabled and image rotated 90 degrees and gravity northwest', function (done) {
|
||||
const expected = fixtures.expected('overlay-cutout-rotated90-gravity-northwest.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@@ -547,7 +543,7 @@ describe('Overlays', function() {
|
||||
cutout: true,
|
||||
gravity: 'northwest'
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(80, info.width);
|
||||
@@ -557,28 +553,27 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Composite RGBA raw buffer onto JPEG', function(done) {
|
||||
it('Composite RGBA raw buffer onto JPEG', function (done) {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.raw()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(2048, 1536)
|
||||
.overlayWith(data, { raw: info })
|
||||
.toBuffer(function(err, data) {
|
||||
.toBuffer(function (err, data) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('overlay-jpeg-with-rgb.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Throws an error when called with an invalid file', function(done) {
|
||||
it('Throws an error when called with an invalid file', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.overlayWith('notfound.png')
|
||||
.toBuffer(function(err) {
|
||||
.toBuffer(function (err) {
|
||||
assert(err instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
describe('Require-time checks', function() {
|
||||
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "(bufferutil|sharp)" }] */
|
||||
|
||||
/*
|
||||
describe('Require-time checks', function () {
|
||||
/**
|
||||
Including sharp alongside another C++ module that does not require
|
||||
-stdlib=libc++ (for its C++11 features) has caused clang/llvm to
|
||||
segfault due to the use of static function variables.
|
||||
*/
|
||||
it('Require alongside C++ module that does not use libc++', function() {
|
||||
var bufferutil = require('bufferutil');
|
||||
var sharp = require('../../index');
|
||||
it('Require alongside C++ module that does not use libc++', function () {
|
||||
const bufferutil = require('bufferutil');
|
||||
const sharp = require('../../index');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Resize dimensions', function() {
|
||||
|
||||
it('Exact crop', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function(err, data, info) {
|
||||
describe('Resize dimensions', function () {
|
||||
it('Exact crop', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -18,8 +17,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fixed width', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320).toBuffer(function(err, data, info) {
|
||||
it('Fixed width', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -29,8 +28,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fixed height', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function(err, data, info) {
|
||||
it('Fixed height', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -40,8 +39,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Identity transform', function(done) {
|
||||
sharp(fixtures.inputJpg).toBuffer(function(err, data, info) {
|
||||
it('Identity transform', function (done) {
|
||||
sharp(fixtures.inputJpg).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -51,8 +50,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(3000).toBuffer(function(err, data, info) {
|
||||
it('Upscale', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(3000).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -62,8 +61,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid width - NaN', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid width - NaN', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize('spoons', 240);
|
||||
} catch (err) {
|
||||
@@ -73,8 +72,8 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Invalid height - NaN', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid height - NaN', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 'spoons');
|
||||
} catch (err) {
|
||||
@@ -84,8 +83,8 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Invalid width - float', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid width - float', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(1.5, 240);
|
||||
} catch (err) {
|
||||
@@ -95,8 +94,8 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Invalid height - float', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid height - float', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 1.5);
|
||||
} catch (err) {
|
||||
@@ -106,8 +105,8 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Invalid width - too large', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid width - too large', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(0x4000, 240);
|
||||
} catch (err) {
|
||||
@@ -117,8 +116,8 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Invalid height - too large', function(done) {
|
||||
var isValid = true;
|
||||
it('Invalid height - too large', function (done) {
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 0x4000);
|
||||
} catch (err) {
|
||||
@@ -129,18 +128,18 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.buffer) {
|
||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function(done) {
|
||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(1080, 607)
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(1080, info.width);
|
||||
assert.strictEqual(607, info.height);
|
||||
sharp(data)
|
||||
.resize(233, 131)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(233, info.width);
|
||||
@@ -152,12 +151,12 @@ describe('Resize dimensions', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.tiff.input.file) {
|
||||
it('TIFF embed known to cause rounding errors', function(done) {
|
||||
it('TIFF embed known to cause rounding errors', function (done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(240, 320)
|
||||
.embed()
|
||||
.jpeg()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -167,11 +166,11 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF known to cause rounding errors', function(done) {
|
||||
it('TIFF known to cause rounding errors', function (done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(240, 320)
|
||||
.jpeg()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -181,8 +180,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Max width or height considering ratio (portrait)', function(done) {
|
||||
sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().toBuffer(function(err, data, info) {
|
||||
it('Max width or height considering ratio (portrait)', function (done) {
|
||||
sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -192,8 +191,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Min width or height considering ratio (portrait)', function(done) {
|
||||
sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().toBuffer(function(err, data, info) {
|
||||
it('Min width or height considering ratio (portrait)', function (done) {
|
||||
sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -204,8 +203,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('Max width or height considering ratio (landscape)', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).max().toBuffer(function(err, data, info) {
|
||||
it('Max width or height considering ratio (landscape)', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).max().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -215,8 +214,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Provide only one dimension with max, should default to crop', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320).max().toBuffer(function(err, data, info) {
|
||||
it('Provide only one dimension with max, should default to crop', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320).max().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -226,8 +225,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Min width or height considering ratio (landscape)', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).min().toBuffer(function(err, data, info) {
|
||||
it('Min width or height considering ratio (landscape)', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).min().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -237,8 +236,8 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Provide only one dimension with min, should default to crop', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320).min().toBuffer(function(err, data, info) {
|
||||
it('Provide only one dimension with min, should default to crop', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320).min().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -248,11 +247,11 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not enlarge when input width is already less than output width', function(done) {
|
||||
it('Do not enlarge when input width is already less than output width', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(2800)
|
||||
.withoutEnlargement()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -262,11 +261,11 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not enlarge when input height is already less than output height', function(done) {
|
||||
it('Do not enlarge when input height is already less than output height', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(null, 2300)
|
||||
.withoutEnlargement()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -276,11 +275,11 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do enlarge when input width is less than output width', function(done) {
|
||||
it('Do enlarge when input width is less than output width', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(2800)
|
||||
.withoutEnlargement(false)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -289,9 +288,9 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale width and height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
|
||||
it('Downscale width and height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -300,9 +299,9 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale width, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
|
||||
it('Downscale width, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -311,82 +310,81 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width and height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale width, upscale height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().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(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width, downscale height, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Identity transform, ignoring aspect ratio', function(done) {
|
||||
sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width and height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Downscale width, upscale height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().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(3000, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale width, downscale height, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Identity transform, ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Rotation', function() {
|
||||
|
||||
['Landscape', 'Portrait'].forEach(function(orientation) {
|
||||
[1,2,3,4,5,6,7,8].forEach(function(exifTag) {
|
||||
it('Input image has Orientation EXIF tag value of (' + exifTag + '), auto-rotate', function(done) {
|
||||
sharp(fixtures['inputJpgWith'+orientation+'Exif'+exifTag])
|
||||
describe('Rotation', function () {
|
||||
['Landscape', 'Portrait'].forEach(function (orientation) {
|
||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
||||
it('Input image has Orientation EXIF tag value of (' + exifTag + '), auto-rotate', function (done) {
|
||||
sharp(fixtures['inputJpgWith' + orientation + 'Exif' + exifTag])
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -24,8 +23,8 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 90 degrees, respecting output input size', function(done) {
|
||||
sharp(fixtures.inputJpg).rotate(90).resize(320, 240).toBuffer(function(err, data, info) {
|
||||
it('Rotate by 90 degrees, respecting output input size', function (done) {
|
||||
sharp(fixtures.inputJpg).rotate(90).resize(320, 240).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -35,16 +34,17 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function(done) {
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(240, 240)
|
||||
.ignoreAspectRatio()
|
||||
.rotate(270)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
done();
|
||||
@@ -52,16 +52,17 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function(done) {
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.ignoreAspectRatio()
|
||||
.rotate(270)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
done();
|
||||
@@ -69,28 +70,29 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', function(done) {
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320)
|
||||
.withMetadata()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.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(427, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(8, metadata.orientation);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function(done) {
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -99,42 +101,44 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', function(done) {
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', function (done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.withMetadata({orientation: 3})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function(done) {
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (done) {
|
||||
sharp(fixtures.inputJpgWithExifMirroring)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.withMetadata()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate using image that has no EXIF', function(done) {
|
||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function(err, data, info) {
|
||||
it('Attempt to auto-rotate using image that has no EXIF', function (done) {
|
||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -144,12 +148,12 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate image format without EXIF support', function(done) {
|
||||
it('Attempt to auto-rotate image format without EXIF support', function (done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.jpeg()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -159,23 +163,23 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate to an invalid angle, should fail', function() {
|
||||
assert.throws(function() {
|
||||
it('Rotate to an invalid angle, should fail', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).rotate(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip - vertical', function(done) {
|
||||
it('Flip - vertical', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip()
|
||||
.withMetadata()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done);
|
||||
@@ -183,17 +187,17 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flop - horizontal', function(done) {
|
||||
it('Flop - horizontal', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flop()
|
||||
.withMetadata()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done);
|
||||
@@ -201,11 +205,11 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip and flop', function(done) {
|
||||
it('Flip and flop', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flop()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -214,12 +218,12 @@ describe('Rotation', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Neither flip nor flop', function(done) {
|
||||
it('Neither flip nor flop', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip(false)
|
||||
.flop(false)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -227,5 +231,4 @@ describe('Rotation', function() {
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Sharpen', function() {
|
||||
|
||||
it('specific radius 10 (sigma 6)', function(done) {
|
||||
describe('Sharpen', function () {
|
||||
it('specific radius 10 (sigma 6)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(6)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -20,11 +19,11 @@ describe('Sharpen', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function(done) {
|
||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(1.5, 0.5, 2.5)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -33,11 +32,11 @@ describe('Sharpen', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', function(done) {
|
||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(3.5, 2, 4)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -47,11 +46,11 @@ describe('Sharpen', function() {
|
||||
});
|
||||
|
||||
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
||||
it('specific radius/levels with alpha channel', function(done) {
|
||||
it('specific radius/levels with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.sharpen(5, 4, 8)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@@ -62,11 +61,11 @@ describe('Sharpen', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('mild sharpen', function(done) {
|
||||
it('mild sharpen', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -75,29 +74,29 @@ describe('Sharpen', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid sigma', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid sigma', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).sharpen(-1.5);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid flat', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid flat', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).sharpen(1, -1);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid jagged', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid jagged', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).sharpen(1, 1, -1);
|
||||
});
|
||||
});
|
||||
|
||||
it('sharpened image is larger than non-sharpened', function(done) {
|
||||
it('sharpened image is larger than non-sharpened', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(false)
|
||||
.toBuffer(function(err, notSharpened, info) {
|
||||
.toBuffer(function (err, notSharpened, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, notSharpened.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@@ -106,7 +105,7 @@ describe('Sharpen', function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(true)
|
||||
.toBuffer(function(err, sharpened, info) {
|
||||
.toBuffer(function (err, sharpened, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, sharpened.length > 0);
|
||||
assert.strictEqual(true, sharpened.length > notSharpened.length);
|
||||
@@ -117,5 +116,4 @@ describe('Sharpen', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Threshold', function() {
|
||||
it('threshold 1 jpeg', function(done) {
|
||||
describe('Threshold', function () {
|
||||
it('threshold 1 jpeg', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(1)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -18,11 +19,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold 40 jpeg', function(done) {
|
||||
it('threshold 40 jpeg', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(40)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -30,11 +32,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold 128', function(done) {
|
||||
it('threshold 128', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -42,11 +45,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold true (=128)', function(done) {
|
||||
it('threshold true (=128)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(true)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -54,19 +58,21 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold false (=0)', function(done) {
|
||||
it('threshold false (=0)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.threshold(false)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold grayscale: true (=128)', function(done) {
|
||||
it('threshold grayscale: true (=128)', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128, { grayscale: true } )
|
||||
.toBuffer(function(err, data, info) {
|
||||
.threshold(128, { grayscale: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -74,11 +80,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default jpeg', function(done) {
|
||||
it('threshold default jpeg', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -86,11 +93,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default png transparency', function(done) {
|
||||
it('threshold default png transparency', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -98,11 +106,12 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default png alpha', function(done) {
|
||||
it('threshold default png alpha', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@@ -110,37 +119,37 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.file) {
|
||||
it('threshold default webp transparency', function(done) {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.threshold()
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
it('threshold default webp transparency', function (done) {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('color threshold', function(done) {
|
||||
it('color threshold', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128,{'grayscale':false})
|
||||
.toBuffer(function(err, data, info) {
|
||||
.threshold(128, {'grayscale': false})
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-color-128.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid threshold -1', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid threshold -1', function () {
|
||||
assert.throws(function () {
|
||||
sharp().threshold(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid threshold 256', function() {
|
||||
assert.throws(function() {
|
||||
it('invalid threshold 256', function () {
|
||||
assert.throws(function () {
|
||||
sharp().threshold(256);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Trim borders', function() {
|
||||
|
||||
it('Threshold default', function(done) {
|
||||
var expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
||||
describe('Trim borders', function () {
|
||||
it('Threshold default', function (done) {
|
||||
const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(450, 322)
|
||||
.trim()
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(450, info.width);
|
||||
@@ -21,11 +20,11 @@ describe('Trim borders', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit PNG with alpha channel', function(done) {
|
||||
it('16-bit PNG with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 32)
|
||||
.trim(20)
|
||||
.toBuffer(function(err, data, info) {
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@@ -36,10 +35,10 @@ describe('Trim borders', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid thresholds', function() {
|
||||
[-1, 100, 'fail', {}].forEach(function(threshold) {
|
||||
it(JSON.stringify(threshold), function() {
|
||||
assert.throws(function() {
|
||||
describe('Invalid thresholds', function () {
|
||||
[-1, 100, 'fail', {}].forEach(function (threshold) {
|
||||
it(JSON.stringify(threshold), function () {
|
||||
assert.throws(function () {
|
||||
sharp().trim(threshold);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
const assert = require('assert');
|
||||
const sharp = require('../../index');
|
||||
|
||||
var defaultConcurrency = sharp.concurrency();
|
||||
const defaultConcurrency = sharp.concurrency();
|
||||
|
||||
describe('Utilities', function() {
|
||||
|
||||
describe('Cache', function() {
|
||||
it('Can be disabled', function() {
|
||||
describe('Utilities', function () {
|
||||
describe('Cache', function () {
|
||||
it('Can be disabled', function () {
|
||||
sharp.cache(false);
|
||||
var cache = sharp.cache(false);
|
||||
const cache = sharp.cache(false);
|
||||
assert.strictEqual(cache.memory.current, 0);
|
||||
assert.strictEqual(cache.memory.max, 0);
|
||||
assert.strictEqual(typeof cache.memory.high, 'number');
|
||||
@@ -20,14 +18,14 @@ describe('Utilities', function() {
|
||||
assert.strictEqual(cache.items.current, 0);
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be enabled with defaults', function() {
|
||||
var cache = sharp.cache(true);
|
||||
it('Can be enabled with defaults', function () {
|
||||
const cache = sharp.cache(true);
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
assert.strictEqual(cache.files.max, 20);
|
||||
assert.strictEqual(cache.items.max, 100);
|
||||
});
|
||||
it('Can be set to zero', function() {
|
||||
var cache = sharp.cache({
|
||||
it('Can be set to zero', function () {
|
||||
const cache = sharp.cache({
|
||||
memory: 0,
|
||||
files: 0,
|
||||
items: 0
|
||||
@@ -36,71 +34,71 @@ describe('Utilities', function() {
|
||||
assert.strictEqual(cache.files.max, 0);
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function() {
|
||||
var cache = sharp.cache({
|
||||
memory: 10,
|
||||
files: 100,
|
||||
items: 1000
|
||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function () {
|
||||
const cache = sharp.cache({
|
||||
memory: 10,
|
||||
files: 100,
|
||||
items: 1000
|
||||
});
|
||||
assert.strictEqual(cache.memory.max, 10);
|
||||
assert.strictEqual(cache.files.max, 100);
|
||||
assert.strictEqual(cache.items.max, 1000);
|
||||
});
|
||||
it('Ignores invalid values', function() {
|
||||
it('Ignores invalid values', function () {
|
||||
sharp.cache(true);
|
||||
var cache = sharp.cache('spoons');
|
||||
const cache = sharp.cache('spoons');
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
assert.strictEqual(cache.files.max, 20);
|
||||
assert.strictEqual(cache.items.max, 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Concurrency', function() {
|
||||
it('Can be set to use 16 threads', function() {
|
||||
describe('Concurrency', function () {
|
||||
it('Can be set to use 16 threads', function () {
|
||||
sharp.concurrency(16);
|
||||
assert.strictEqual(16, sharp.concurrency());
|
||||
});
|
||||
it('Can be reset to default', function() {
|
||||
it('Can be reset to default', function () {
|
||||
sharp.concurrency(0);
|
||||
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
||||
});
|
||||
it('Ignores invalid values', function() {
|
||||
it('Ignores invalid values', function () {
|
||||
sharp.concurrency(0);
|
||||
sharp.concurrency('spoons');
|
||||
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Counters', function() {
|
||||
it('Have zero value at rest', function() {
|
||||
var counters = sharp.counters();
|
||||
describe('Counters', function () {
|
||||
it('Have zero value at rest', function () {
|
||||
const counters = sharp.counters();
|
||||
assert.strictEqual(0, counters.queue);
|
||||
assert.strictEqual(0, counters.process);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SIMD', function() {
|
||||
it('Can get current state', function() {
|
||||
var simd = sharp.simd();
|
||||
describe('SIMD', function () {
|
||||
it('Can get current state', function () {
|
||||
const simd = sharp.simd();
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
it('Can disable', function() {
|
||||
var simd = sharp.simd(false);
|
||||
it('Can disable', function () {
|
||||
const simd = sharp.simd(false);
|
||||
assert.strictEqual(simd, false);
|
||||
});
|
||||
it('Can attempt to enable', function() {
|
||||
var simd = sharp.simd(true);
|
||||
it('Can attempt to enable', function () {
|
||||
const simd = sharp.simd(true);
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Format', function() {
|
||||
it('Contains expected attributes', function() {
|
||||
describe('Format', function () {
|
||||
it('Contains expected attributes', function () {
|
||||
assert.strictEqual('object', typeof sharp.format);
|
||||
Object.keys(sharp.format).forEach(function(format) {
|
||||
Object.keys(sharp.format).forEach(function (format) {
|
||||
assert.strictEqual(true, 'id' in sharp.format[format]);
|
||||
assert.strictEqual(format, sharp.format[format].id);
|
||||
['input', 'output'].forEach(function(direction) {
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
assert.strictEqual(true, direction in sharp.format[format]);
|
||||
assert.strictEqual('object', typeof sharp.format[format][direction]);
|
||||
assert.strictEqual(3, Object.keys(sharp.format[format][direction]).length);
|
||||
@@ -113,8 +111,8 @@ describe('Utilities', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('Raw file=false, buffer=true, stream=true', function() {
|
||||
['input', 'output'].forEach(function(direction) {
|
||||
it('Raw file=false, buffer=true, stream=true', function () {
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
assert.strictEqual(false, sharp.format.raw[direction].file);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].buffer);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].stream);
|
||||
@@ -122,11 +120,10 @@ describe('Utilities', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Versions', function() {
|
||||
it('Contains expected attributes', function() {
|
||||
describe('Versions', function () {
|
||||
it('Contains expected attributes', function () {
|
||||
assert.strictEqual('object', typeof sharp.versions);
|
||||
assert.strictEqual('string', typeof sharp.versions.vips);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user