mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Update tests to meet semistandard code standards
Switch to const/let instead of var
This commit is contained in:
parent
36e636dca1
commit
cbdbbe535a
@ -1,4 +1,6 @@
|
||||
machine:
|
||||
node:
|
||||
version: v4.6.1
|
||||
services:
|
||||
- docker
|
||||
test:
|
||||
|
@ -87,9 +87,6 @@
|
||||
"semistandard": {
|
||||
"env": [
|
||||
"mocha"
|
||||
],
|
||||
"ignore": [
|
||||
"test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -2,24 +2,24 @@
|
||||
|
||||
process.env.UV_THREADPOOL_SIZE = 64;
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
const assert = require('assert');
|
||||
const async = require('async');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
var width = 720;
|
||||
var height = 480;
|
||||
const width = 720;
|
||||
const height = 480;
|
||||
|
||||
sharp.concurrency(1);
|
||||
sharp.simd(true);
|
||||
|
||||
var timer = setInterval(function() {
|
||||
const timer = setInterval(function () {
|
||||
console.dir(sharp.counters());
|
||||
}, 100);
|
||||
|
||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
||||
var start = new Date().getTime();
|
||||
const start = new Date().getTime();
|
||||
async.times(parallelism,
|
||||
function (id, callback) {
|
||||
/* jslint unused: false */
|
||||
@ -31,7 +31,7 @@ async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function(parallelism, next) {
|
||||
function (err, ids) {
|
||||
assert(!err);
|
||||
assert(ids.length === parallelism);
|
||||
var mean = ids.reduce(function(a, b) {
|
||||
const mean = ids.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}) / ids.length;
|
||||
console.log(parallelism + ' parallel calls: fastest=' + ids[0] + 'ms slowest=' + ids[ids.length - 1] + 'ms mean=' + mean + 'ms');
|
||||
|
@ -1,34 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var Benchmark = require('benchmark');
|
||||
var semver = require('semver');
|
||||
const async = require('async');
|
||||
const assert = require('assert');
|
||||
const Benchmark = require('benchmark');
|
||||
|
||||
// Contenders
|
||||
var gm = require('gm');
|
||||
var imagemagick = require('imagemagick');
|
||||
var jimp = require('jimp');
|
||||
var sharp = require('../../');
|
||||
var imagemagickNative;
|
||||
const gm = require('gm');
|
||||
const imagemagick = require('imagemagick');
|
||||
const jimp = require('jimp');
|
||||
const sharp = require('../../');
|
||||
let imagemagickNative;
|
||||
try {
|
||||
imagemagickNative = require('imagemagick-native');
|
||||
} catch (err) {
|
||||
console.log('Excluding imagemagick-native');
|
||||
}
|
||||
var lwip;
|
||||
let lwip;
|
||||
try {
|
||||
lwip = require('lwip');
|
||||
} catch (err) {
|
||||
console.log('Excluding lwip');
|
||||
}
|
||||
|
||||
var fixtures = require('../fixtures');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
var width = 720;
|
||||
var height = 480;
|
||||
const width = 720;
|
||||
const height = 480;
|
||||
|
||||
// Disable libvips cache to ensure tests are as fair as they can be
|
||||
sharp.cache(false);
|
||||
@ -37,17 +36,17 @@ sharp.simd(true);
|
||||
|
||||
async.series({
|
||||
'jpeg': function (callback) {
|
||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
var jpegSuite = new Benchmark.Suite('jpeg');
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const jpegSuite = new Benchmark.Suite('jpeg');
|
||||
// jimp
|
||||
jpegSuite.add('jimp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
new jimp(inputJpgBuffer, function(err) {
|
||||
jimp.read(inputJpgBuffer, function (err, image) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
this
|
||||
image
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.getBuffer(jimp.MIME_JPEG, function (err) {
|
||||
@ -63,11 +62,11 @@ async.series({
|
||||
}).add('jimp-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
new jimp(fixtures.inputJpg, function(err) {
|
||||
jimp.read(fixtures.inputJpg, function (err, image) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
this
|
||||
image
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.write(fixtures.outputJpg, function (err) {
|
||||
@ -278,12 +277,12 @@ async.series({
|
||||
}).add('sharp-stream-stream', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
writable.on('finish', function () {
|
||||
deferred.resolve();
|
||||
});
|
||||
var pipeline = sharp()
|
||||
const pipeline = sharp()
|
||||
.resize(width, height);
|
||||
readable.pipe(pipeline).pipe(writable);
|
||||
}
|
||||
@ -320,8 +319,8 @@ async.series({
|
||||
},
|
||||
// Effect of applying operations
|
||||
operations: function (callback) {
|
||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
var operationsSuite = new Benchmark.Suite('operations');
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const operationsSuite = new Benchmark.Suite('operations');
|
||||
operationsSuite.add('sharp-sharpen-mild', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
@ -557,7 +556,7 @@ async.series({
|
||||
},
|
||||
// Comparitive speed of kernels
|
||||
kernels: function (callback) {
|
||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
@ -608,17 +607,17 @@ async.series({
|
||||
},
|
||||
// PNG
|
||||
png: function (callback) {
|
||||
var inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||
var pngSuite = new Benchmark.Suite('png');
|
||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||
const pngSuite = new Benchmark.Suite('png');
|
||||
// jimp
|
||||
pngSuite.add('jimp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
new jimp(inputPngBuffer, function(err) {
|
||||
jimp.read(inputPngBuffer, function (err, image) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
this
|
||||
image
|
||||
.resize(width, height)
|
||||
.getBuffer(jimp.MIME_PNG, function (err) {
|
||||
if (err) {
|
||||
@ -633,11 +632,11 @@ async.series({
|
||||
}).add('jimp-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
new jimp(fixtures.inputPng, function(err) {
|
||||
jimp.read(fixtures.inputPng, function (err, image) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
this
|
||||
image
|
||||
.resize(width, height)
|
||||
.write(fixtures.outputPng, function (err) {
|
||||
if (err) {
|
||||
@ -835,7 +834,7 @@ async.series({
|
||||
},
|
||||
// WebP
|
||||
webp: function (callback) {
|
||||
var inputWebPBuffer = fs.readFileSync(fixtures.inputWebP);
|
||||
const inputWebPBuffer = fs.readFileSync(fixtures.inputWebP);
|
||||
(new Benchmark.Suite('webp')).add('sharp-buffer-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
|
@ -1,20 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var imagemagick = require('imagemagick');
|
||||
var gm = require('gm');
|
||||
var assert = require('assert');
|
||||
var Benchmark = require('benchmark');
|
||||
const imagemagick = require('imagemagick');
|
||||
const gm = require('gm');
|
||||
const assert = require('assert');
|
||||
const Benchmark = require('benchmark');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(false);
|
||||
sharp.simd(true);
|
||||
|
||||
var min = 320;
|
||||
var max = 960;
|
||||
const min = 320;
|
||||
const max = 960;
|
||||
|
||||
var randomDimension = function() {
|
||||
const randomDimension = function () {
|
||||
return Math.ceil(Math.random() * (max - min) + min);
|
||||
};
|
||||
|
||||
@ -70,6 +70,6 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
}).on('cycle', function (event) {
|
||||
console.log(String(event.target));
|
||||
}).on('complete', function () {
|
||||
var winner = this.filter('fastest').map('name');
|
||||
const winner = this.filter('fastest').map('name');
|
||||
assert.strictEqual('sharp', String(winner), 'sharp was slower than ' + winner);
|
||||
}).run();
|
||||
|
@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
const fs = require('fs');
|
||||
const request = require('request');
|
||||
@ -21,8 +20,7 @@ const fetchImages = function(offset) {
|
||||
response.posts.forEach((post) => {
|
||||
const url = post.photos[0].alt_sizes
|
||||
.filter((image) => image.width === 100)
|
||||
.map((image) => image.url)
|
||||
[0];
|
||||
.map((image) => image.url)[0];
|
||||
const filename = `./images/${post.id}.jpg`;
|
||||
try {
|
||||
fs.statSync(filename);
|
||||
|
@ -1,8 +1,7 @@
|
||||
'use strict';
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
const fs = require('fs');
|
||||
const child_process = require('child_process');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
const a = [];
|
||||
const b = [];
|
||||
@ -12,7 +11,7 @@ fs.readdirSync('./images')
|
||||
.forEach((file) => {
|
||||
// Extract one pixel, avoiding first DCT block, and return value of A and B channels
|
||||
const command = `convert ./images/${file}[1x1+8+8] -colorspace lab -format "%[fx:u.g] %[fx:u.b]" info:`;
|
||||
const result = child_process.execSync(command, { encoding: 'utf8' });
|
||||
const result = childProcess.execSync(command, { encoding: 'utf8' });
|
||||
const ab = result.split(' ');
|
||||
a.push(ab[0]);
|
||||
b.push(ab[1]);
|
||||
|
@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
@ -42,7 +41,7 @@ async.eachLimit(files, concurrency, function(file, done) {
|
||||
sharp(filename).resize(salientWidth, metadata.height).crop(crops[crop]).toBuffer(function (err, data, info) {
|
||||
const accuracy = Math.round(Math.abs(userData[file].left - info.cropCalcLeft) / (metadata.width - salientWidth) * 100);
|
||||
incrementScore(accuracy, crop);
|
||||
done();
|
||||
done(err);
|
||||
});
|
||||
},
|
||||
// Top edge accuracy
|
||||
@ -50,7 +49,7 @@ async.eachLimit(files, concurrency, function(file, done) {
|
||||
sharp(filename).resize(metadata.width, salientHeight).crop(crops[crop]).toBuffer(function (err, data, info) {
|
||||
const accuracy = Math.round(Math.abs(userData[file].top - info.cropCalcTop) / (metadata.height - salientHeight) * 100);
|
||||
incrementScore(accuracy, crop);
|
||||
done();
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
], done);
|
||||
|
@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
/*jshint esversion: 6, loopfunc: true */
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
@ -39,7 +38,10 @@ fs.readdirSync(userDataDir).forEach(function(file) {
|
||||
const regions = lines[linePos].split('; ');
|
||||
linePos = linePos + 2;
|
||||
// Parse human-labelled regions for min/max coords
|
||||
const lefts = [], tops = [], rights = [], bottoms = [];
|
||||
const lefts = [];
|
||||
const tops = [];
|
||||
const rights = [];
|
||||
const bottoms = [];
|
||||
regions.forEach(function (region) {
|
||||
if (region.indexOf(' ') !== -1) {
|
||||
const coords = region.split(' ');
|
||||
|
@ -1,11 +1,10 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten()
|
||||
@ -45,7 +44,7 @@ describe('Alpha transparency', function() {
|
||||
});
|
||||
|
||||
it('Flatten 16-bit PNG with transparency to orange', function (done) {
|
||||
var output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
const output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.flatten()
|
||||
.background({r: 255, g: 102, b: 0})
|
||||
@ -83,9 +82,9 @@ 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);
|
||||
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) {
|
||||
@ -99,9 +98,9 @@ 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);
|
||||
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) {
|
||||
@ -113,5 +112,4 @@ describe('Alpha transparency', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,11 +1,10 @@
|
||||
'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('Bandbool per-channel boolean operations', function () {
|
||||
|
||||
[
|
||||
sharp.bool.and,
|
||||
sharp.bool.or,
|
||||
@ -30,6 +29,7 @@ describe('Bandbool per-channel boolean operations', function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.bandbool('and')
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, info.channels);
|
||||
done();
|
||||
});
|
||||
|
@ -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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -24,6 +24,7 @@ describe('Blur', function() {
|
||||
.resize(320, 240)
|
||||
.blur(10)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -36,6 +37,7 @@ describe('Blur', function() {
|
||||
.resize(320, 240)
|
||||
.blur(0.3)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -48,6 +50,7 @@ describe('Blur', function() {
|
||||
.resize(320, 240)
|
||||
.blur()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -66,6 +69,7 @@ describe('Blur', function() {
|
||||
.resize(320, 240)
|
||||
.blur(false)
|
||||
.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);
|
||||
@ -74,6 +78,7 @@ describe('Blur', function() {
|
||||
.resize(320, 240)
|
||||
.blur(true)
|
||||
.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,13 +1,13 @@
|
||||
'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');
|
||||
|
||||
describe('Boolean operation between two images', function () {
|
||||
|
||||
var inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||
const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||
|
||||
[
|
||||
sharp.bool.and,
|
||||
@ -15,7 +15,6 @@ describe('Boolean operation between two images', function() {
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function (op) {
|
||||
|
||||
it(op + ' operation, file', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
@ -56,7 +55,6 @@ describe('Boolean operation between two images', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Invalid operation', function () {
|
||||
|
@ -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);
|
||||
sharp.cache(!process.env.SHARP_TEST_WITHOUT_CACHE);
|
||||
});
|
||||
|
@ -1,13 +1,12 @@
|
||||
'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 () {
|
||||
sharp.cache(false);
|
||||
});
|
||||
@ -16,10 +15,10 @@ describe('Clone', function() {
|
||||
});
|
||||
|
||||
it('Read from Stream and write to multiple Streams', function (done) {
|
||||
var finishEventsExpected = 2;
|
||||
let finishEventsExpected = 2;
|
||||
// Output stream 1
|
||||
var output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||
var writable1 = fs.createWriteStream(output1);
|
||||
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;
|
||||
@ -36,8 +35,8 @@ describe('Clone', function() {
|
||||
});
|
||||
});
|
||||
// Output stream 2
|
||||
var output2 = fixtures.path('output.multi-stream.2.jpg');
|
||||
var writable2 = fs.createWriteStream(output2);
|
||||
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;
|
||||
@ -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,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputPngStripesV)
|
||||
.convolve({
|
||||
|
@ -1,20 +1,19 @@
|
||||
'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/');
|
||||
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) {
|
||||
return source !== 'libvips';
|
||||
}).forEach(function (source) {
|
||||
var file = path.join('src', source);
|
||||
const file = path.join('src', source);
|
||||
it(file, function (done) {
|
||||
// Lint each source file
|
||||
cpplint({
|
||||
@ -38,14 +37,12 @@ describe('cpplint', function() {
|
||||
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');
|
||||
const sharp = require('../../index');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Crop', function () {
|
||||
|
||||
[
|
||||
{
|
||||
name: 'North',
|
||||
@ -161,7 +160,6 @@ describe('Crop', function() {
|
||||
});
|
||||
|
||||
describe('Entropy-based strategy', function () {
|
||||
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(80, 320)
|
||||
@ -193,11 +191,9 @@ describe('Crop', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Attention strategy', function () {
|
||||
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(80, 320)
|
||||
@ -229,6 +225,5 @@ describe('Crop', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.embed()
|
||||
@ -118,5 +117,4 @@ describe('Embed', function() {
|
||||
fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(120)
|
||||
@ -55,10 +54,10 @@ describe('Extend', function () {
|
||||
.toFormat(sharp.format.png)
|
||||
.extend({top: 0, bottom: 10, left: 0, right: 10})
|
||||
.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,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
||||
@ -181,7 +180,7 @@ describe('Partial image extraction', function() {
|
||||
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
||||
.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,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('red')
|
||||
@ -77,5 +76,4 @@ describe('Image channel extraction', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
'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 () {
|
||||
@ -16,7 +16,7 @@ describe('Test fixtures', function() {
|
||||
});
|
||||
});
|
||||
it('should accept a zero threshold when comparing an image to itself', function () {
|
||||
var image = fixtures.inputPngOverlayLayer0;
|
||||
const image = fixtures.inputPngOverlayLayer0;
|
||||
fixtures.assertMaxColourDistance(image, image, 0);
|
||||
});
|
||||
it('should accept a numeric threshold for two different images', function () {
|
||||
|
@ -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) {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@ -23,6 +23,7 @@ describe('Gamma correction', function() {
|
||||
.resize(129, 111)
|
||||
.gamma()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@ -35,6 +36,7 @@ describe('Gamma correction', function() {
|
||||
.resize(129, 111)
|
||||
.gamma(3)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
assert.strictEqual(111, info.height);
|
||||
@ -47,6 +49,7 @@ describe('Gamma correction', function() {
|
||||
.resize(320)
|
||||
.gamma()
|
||||
.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);
|
||||
@ -58,5 +61,4 @@ describe('Gamma correction', function() {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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 () {
|
||||
[
|
||||
sharp.kernel.cubic,
|
||||
@ -59,5 +58,4 @@ describe('Interpolators and kernels', function() {
|
||||
sharp().resize(null, null, { interpolator: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
100
test/unit/io.js
100
test/unit/io.js
@ -1,13 +1,12 @@
|
||||
'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('Input/output', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
sharp.cache(false);
|
||||
});
|
||||
@ -16,7 +15,7 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from File and write to Stream', function (done) {
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
writable.on('finish', function () {
|
||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
@ -33,8 +32,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from Buffer and write to Stream', function (done) {
|
||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
writable.on('finish', function () {
|
||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
@ -51,8 +50,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from Stream and write to File', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function(err, info) {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function (err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -65,8 +64,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Buffer', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp().resize(320, 240).toBuffer(function(err, data, info) {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -79,8 +78,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Buffer via Promise', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp().resize(1, 1);
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().resize(1, 1);
|
||||
pipeline.toBuffer().then(function (data) {
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
done();
|
||||
@ -91,8 +90,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Stream', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
writable.on('finish', function () {
|
||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
@ -105,15 +104,15 @@ describe('Input/output', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
var pipeline = sharp().resize(320, 240);
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
readable.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Stream should emit info event', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
var pipeline = sharp().resize(320, 240);
|
||||
var infoEventEmitted = false;
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
let infoEventEmitted = false;
|
||||
pipeline.on('info', function (info) {
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -130,8 +129,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Handle Stream to Stream error ', function (done) {
|
||||
var pipeline = sharp().resize(320, 240);
|
||||
var anErrorWasEmitted = false;
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
let anErrorWasEmitted = false;
|
||||
pipeline.on('error', function (err) {
|
||||
anErrorWasEmitted = !!err;
|
||||
}).on('end', function () {
|
||||
@ -139,14 +138,14 @@ describe('Input/output', function() {
|
||||
fs.unlinkSync(fixtures.outputJpg);
|
||||
done();
|
||||
});
|
||||
var readableButNotAnImage = fs.createReadStream(__filename);
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const readableButNotAnImage = fs.createReadStream(__filename);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Handle File to Stream error', function (done) {
|
||||
var readableButNotAnImage = sharp(__filename).resize(320, 240);
|
||||
var anErrorWasEmitted = false;
|
||||
const readableButNotAnImage = sharp(__filename).resize(320, 240);
|
||||
let anErrorWasEmitted = false;
|
||||
readableButNotAnImage.on('error', function (err) {
|
||||
anErrorWasEmitted = !!err;
|
||||
}).on('end', function () {
|
||||
@ -154,7 +153,7 @@ describe('Input/output', function() {
|
||||
fs.unlinkSync(fixtures.outputJpg);
|
||||
done();
|
||||
});
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
readableButNotAnImage.pipe(writable);
|
||||
});
|
||||
|
||||
@ -387,7 +386,7 @@ describe('Input/output', function() {
|
||||
}
|
||||
|
||||
it('Invalid output format', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().toFormat('zoinks');
|
||||
isValid = true;
|
||||
@ -413,7 +412,6 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
describe('Output filename with unknown extension', function () {
|
||||
|
||||
it('Match JPEG input', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 80)
|
||||
@ -500,9 +498,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
describe('PNG output', function () {
|
||||
|
||||
it('compression level is valid', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().compressionLevel(0);
|
||||
isValid = true;
|
||||
@ -512,7 +509,7 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('compression level is invalid', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().compressionLevel(-1);
|
||||
isValid = true;
|
||||
@ -662,7 +659,7 @@ describe('Input/output', function() {
|
||||
assert.strictEqual(320, withInfo.width);
|
||||
assert.strictEqual(240, withInfo.height);
|
||||
// Verify image is of a different size (progressive output even without mozjpeg)
|
||||
assert.strictEqual(true, withData.length != withoutData.length);
|
||||
assert.notEqual(withData.length, withoutData.length);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -725,7 +722,7 @@ describe('Input/output', function() {
|
||||
|
||||
if (sharp.format.tiff.input.buffer) {
|
||||
it('Load TIFF from Buffer', function (done) {
|
||||
var inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||
sharp(inputTiffBuffer)
|
||||
.resize(320, 240)
|
||||
.jpeg()
|
||||
@ -743,7 +740,7 @@ describe('Input/output', function() {
|
||||
|
||||
if (sharp.format.gif.input.buffer) {
|
||||
it('Load GIF from Buffer', function (done) {
|
||||
var inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
||||
const inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
||||
sharp(inputGifBuffer)
|
||||
.resize(320, 240)
|
||||
.jpeg()
|
||||
@ -778,7 +775,7 @@ describe('Input/output', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.v.input.file) {
|
||||
it("Load Vips V file", function(done) {
|
||||
it('Load Vips V file', function (done) {
|
||||
sharp(fixtures.inputV)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
@ -793,7 +790,7 @@ describe('Input/output', function() {
|
||||
}
|
||||
|
||||
if (sharp.format.v.output.file) {
|
||||
it("Save Vips V file", function(done) {
|
||||
it('Save Vips V file', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({left: 910, top: 1105, width: 70, height: 60})
|
||||
.toFile(fixtures.outputV, function (err, info) {
|
||||
@ -816,6 +813,7 @@ describe('Input/output', function() {
|
||||
.resize(32, 24)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 1, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
assert.strictEqual('raw', info.format);
|
||||
@ -829,6 +827,7 @@ describe('Input/output', function() {
|
||||
.resize(32, 24)
|
||||
.toFormat('raw')
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 3, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
assert.strictEqual('raw', info.format);
|
||||
@ -842,6 +841,7 @@ describe('Input/output', function() {
|
||||
.resize(32, 24)
|
||||
.toFormat(sharp.format.raw)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 4, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
assert.strictEqual('raw', info.format);
|
||||
@ -854,9 +854,8 @@ describe('Input/output', function() {
|
||||
}
|
||||
|
||||
describe('Limit pixel count of input image', function () {
|
||||
|
||||
it('Invalid fails - negative', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().limitInputPixels(-1);
|
||||
isValid = true;
|
||||
@ -866,7 +865,7 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Invalid fails - float', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().limitInputPixels(12.3);
|
||||
isValid = true;
|
||||
@ -876,7 +875,7 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Invalid fails - string', function (done) {
|
||||
var isValid = false;
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().limitInputPixels('fail');
|
||||
isValid = true;
|
||||
@ -927,7 +926,6 @@ describe('Input/output', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Input options', function () {
|
||||
@ -1034,8 +1032,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Queue length change events', function (done) {
|
||||
var eventCounter = 0;
|
||||
var queueListener = function(queueLength) {
|
||||
let eventCounter = 0;
|
||||
const queueListener = function (queueLength) {
|
||||
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
||||
eventCounter++;
|
||||
};
|
||||
@ -1053,8 +1051,8 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
it('Info event data', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
var inPipeline = sharp()
|
||||
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
const inPipeline = sharp()
|
||||
.resize(840, 472)
|
||||
.raw()
|
||||
.on('info', function (info) {
|
||||
@ -1062,20 +1060,16 @@ describe('Input/output', function() {
|
||||
assert.strictEqual(472, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
});
|
||||
var badPipeline = sharp(null, {raw: {width: 840, height: 500, channels: 3}})
|
||||
const badPipeline = sharp(null, {raw: {width: 840, height: 500, channels: 3}})
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
||||
readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
var goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}})
|
||||
const goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}})
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
inPipeline = sharp()
|
||||
.resize(840, 472)
|
||||
.raw();
|
||||
readable.pipe(inPipeline).pipe(goodPipeline);
|
||||
});
|
||||
readable.pipe(inPipeline).pipe(badPipeline);
|
||||
|
@ -1,15 +1,14 @@
|
||||
'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) {
|
||||
if (err) throw err;
|
||||
@ -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();
|
||||
@ -215,8 +214,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
|
||||
it('Stream in, Promise out', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp();
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp();
|
||||
pipeline.metadata().then(function (metadata) {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@ -237,8 +236,8 @@ describe('Image metadata', function() {
|
||||
});
|
||||
|
||||
it('Stream', function (done) {
|
||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
||||
var pipeline = sharp().metadata(function(err, metadata) {
|
||||
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);
|
||||
@ -257,7 +256,7 @@ describe('Image metadata', function() {
|
||||
});
|
||||
|
||||
it('Resize to half width using metadata', function (done) {
|
||||
var image = sharp(fixtures.inputJpg);
|
||||
const image = sharp(fixtures.inputJpg);
|
||||
image.metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
@ -294,14 +293,14 @@ describe('Image metadata', function() {
|
||||
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);
|
||||
|
@ -1,9 +1,9 @@
|
||||
'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) {
|
||||
@ -11,6 +11,7 @@ describe('Negate', function() {
|
||||
.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);
|
||||
@ -23,6 +24,7 @@ describe('Negate', function() {
|
||||
.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);
|
||||
@ -35,6 +37,7 @@ describe('Negate', function() {
|
||||
.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);
|
||||
@ -47,6 +50,7 @@ describe('Negate', function() {
|
||||
.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);
|
||||
@ -54,12 +58,12 @@ describe('Negate', function() {
|
||||
});
|
||||
});
|
||||
|
||||
if (sharp.format.webp.output.file) {
|
||||
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);
|
||||
@ -72,19 +76,20 @@ describe('Negate', function() {
|
||||
.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) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -93,11 +98,11 @@ describe('Negate', function() {
|
||||
});
|
||||
|
||||
it('negate (false)', function (done) {
|
||||
var output = fixtures.path('output.unmodified-by-negate.png');
|
||||
const output = fixtures.path('output.unmodified-by-negate.png');
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.negate(false)
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) done(err);
|
||||
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,7 +17,6 @@ var assertNormalized = function(data) {
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
|
||||
it('uses the same prototype for both spellings', function () {
|
||||
assert.strictEqual(sharp.prototype.normalize, sharp.prototype.normalise);
|
||||
});
|
||||
@ -88,7 +87,7 @@ 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');
|
||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toFile(output, function (err, info) {
|
||||
@ -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');
|
||||
const paths = getPaths('alpha-layer-01');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
@ -31,7 +32,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Overlay transparent PNG Buffer on solid background', function (done) {
|
||||
var paths = getPaths('alpha-layer-01');
|
||||
const paths = getPaths('alpha-layer-01');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fs.readFileSync(fixtures.inputPngOverlayLayer1))
|
||||
@ -43,7 +44,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Overlay low-alpha transparent PNG on solid background', function (done) {
|
||||
var paths = getPaths('alpha-layer-01-low-alpha');
|
||||
const paths = getPaths('alpha-layer-01-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
@ -55,7 +56,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite three transparent PNGs into one', function (done) {
|
||||
var paths = getPaths('alpha-layer-012');
|
||||
const paths = getPaths('alpha-layer-012');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||
@ -72,7 +73,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite two transparent PNGs into one', function (done) {
|
||||
var paths = getPaths('alpha-layer-12');
|
||||
const paths = getPaths('alpha-layer-12');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer2)
|
||||
@ -84,7 +85,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite two low-alpha transparent PNGs into one', function (done) {
|
||||
var paths = getPaths('alpha-layer-12-low-alpha');
|
||||
const paths = getPaths('alpha-layer-12-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer2LowAlpha)
|
||||
@ -96,7 +97,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite three low-alpha transparent PNGs into one', function (done) {
|
||||
var paths = getPaths('alpha-layer-012-low-alpha');
|
||||
const paths = getPaths('alpha-layer-012-low-alpha');
|
||||
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||
@ -114,7 +115,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite rgb+alpha PNG onto JPEG', function (done) {
|
||||
var paths = getPaths('overlay-jpeg-with-rgb', 'jpg');
|
||||
const paths = getPaths('overlay-jpeg-with-rgb', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(2048, 1536)
|
||||
@ -127,7 +128,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Composite greyscale+alpha PNG onto JPEG', function (done) {
|
||||
var paths = getPaths('overlay-jpeg-with-greyscale', 'jpg');
|
||||
const paths = getPaths('overlay-jpeg-with-greyscale', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400, 300)
|
||||
@ -141,7 +142,7 @@ describe('Overlays', function() {
|
||||
|
||||
if (sharp.format.webp.input.file) {
|
||||
it('Composite WebP onto JPEG', function (done) {
|
||||
var paths = getPaths('overlay-jpeg-with-webp', 'jpg');
|
||||
const paths = getPaths('overlay-jpeg-with-webp', 'jpg');
|
||||
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(300, 300)
|
||||
@ -212,7 +213,7 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -233,7 +234,7 @@ 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');
|
||||
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -254,7 +255,7 @@ 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');
|
||||
const expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -273,9 +274,9 @@ describe('Overlays', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Overlay with top-left offsets", 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');
|
||||
const expected = fixtures.expected('overlay-valid-offsets-10-10.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -288,11 +289,10 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const expected = fixtures.expected('overlay-valid-offsets-100-300.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -305,7 +305,6 @@ describe('Overlays', function() {
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with only top offset', function () {
|
||||
@ -340,7 +339,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Overlay with 0 offset', function (done) {
|
||||
var expected = fixtures.expected('overlay-offset-0.jpg');
|
||||
const expected = fixtures.expected('overlay-offset-0.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -353,11 +352,10 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const expected = fixtures.expected('overlay-offset-with-gravity.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -372,11 +370,10 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const expected = fixtures.expected('overlay-offset-with-gravity-tile.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -391,11 +388,10 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const expected = fixtures.expected('overlay-offset-with-tile.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -424,7 +420,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('Overlay with very large offset', function (done) {
|
||||
var expected = fixtures.expected('overlay-very-large-offset.jpg');
|
||||
const expected = fixtures.expected('overlay-very-large-offset.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -462,7 +458,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('With tile enabled and image rotated 90 degrees', function (done) {
|
||||
var expected = fixtures.expected('overlay-tile-rotated90.jpg');
|
||||
const expected = fixtures.expected('overlay-tile-rotated90.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@ -480,7 +476,7 @@ 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');
|
||||
const expected = fixtures.expected('overlay-tile-rotated90-gravity-northwest.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@ -501,7 +497,7 @@ 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');
|
||||
const expected = fixtures.expected('overlay-cutout-gravity-' + gravity + '.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
@ -521,7 +517,7 @@ describe('Overlays', function() {
|
||||
});
|
||||
|
||||
it('With cutout enabled and image rotated 90 degrees', function (done) {
|
||||
var expected = fixtures.expected('overlay-cutout-rotated90.jpg');
|
||||
const expected = fixtures.expected('overlay-cutout-rotated90.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@ -539,7 +535,7 @@ 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');
|
||||
const expected = fixtures.expected('overlay-cutout-rotated90-gravity-northwest.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(80)
|
||||
@ -580,5 +576,4 @@ describe('Overlays', function() {
|
||||
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');
|
||||
const bufferutil = require('bufferutil');
|
||||
const sharp = require('../../index');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
if (err) throw err;
|
||||
@ -63,7 +62,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid width - NaN', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize('spoons', 240);
|
||||
} catch (err) {
|
||||
@ -74,7 +73,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid height - NaN', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 'spoons');
|
||||
} catch (err) {
|
||||
@ -85,7 +84,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid width - float', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(1.5, 240);
|
||||
} catch (err) {
|
||||
@ -96,7 +95,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid height - float', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 1.5);
|
||||
} catch (err) {
|
||||
@ -107,7 +106,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid width - too large', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(0x4000, 240);
|
||||
} catch (err) {
|
||||
@ -118,7 +117,7 @@ describe('Resize dimensions', function() {
|
||||
});
|
||||
|
||||
it('Invalid height - too large', function (done) {
|
||||
var isValid = true;
|
||||
let isValid = true;
|
||||
try {
|
||||
sharp(fixtures.inputJpg).resize(320, 0x4000);
|
||||
} catch (err) {
|
||||
@ -388,5 +387,4 @@ describe('Resize dimensions', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
@ -45,6 +44,7 @@ describe('Rotation', function() {
|
||||
assert.strictEqual(240, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
done();
|
||||
@ -62,6 +62,7 @@ describe('Rotation', function() {
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
done();
|
||||
@ -80,6 +81,7 @@ describe('Rotation', function() {
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(427, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(8, metadata.orientation);
|
||||
done();
|
||||
});
|
||||
@ -110,6 +112,7 @@ describe('Rotation', function() {
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
||||
});
|
||||
@ -127,6 +130,7 @@ describe('Rotation', function() {
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
||||
});
|
||||
@ -227,5 +231,4 @@ describe('Rotation', function() {
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,12 +1,11 @@
|
||||
'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) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
@ -117,5 +116,4 @@ describe('Sharpen', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
'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) {
|
||||
@ -11,6 +11,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -23,6 +24,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold(40)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -35,6 +37,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold(128)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -47,6 +50,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold(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);
|
||||
@ -58,6 +62,7 @@ describe('Threshold', function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.threshold(false)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
@ -67,6 +72,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.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);
|
||||
@ -79,6 +85,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -91,6 +98,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -103,6 +111,7 @@ describe('Threshold', function() {
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.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,22 +119,22 @@ 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) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('color threshold', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.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);
|
||||
|
@ -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('Trim borders', function () {
|
||||
|
||||
it('Threshold default', function (done) {
|
||||
var expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
||||
const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(450, 322)
|
||||
.trim()
|
||||
|
@ -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 () {
|
||||
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');
|
||||
@ -21,13 +19,13 @@ describe('Utilities', function() {
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be enabled with defaults', function () {
|
||||
var cache = sharp.cache(true);
|
||||
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({
|
||||
const cache = sharp.cache({
|
||||
memory: 0,
|
||||
files: 0,
|
||||
items: 0
|
||||
@ -37,7 +35,7 @@ describe('Utilities', function() {
|
||||
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({
|
||||
const cache = sharp.cache({
|
||||
memory: 10,
|
||||
files: 100,
|
||||
items: 1000
|
||||
@ -48,7 +46,7 @@ describe('Utilities', 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);
|
||||
@ -73,7 +71,7 @@ describe('Utilities', function() {
|
||||
|
||||
describe('Counters', function () {
|
||||
it('Have zero value at rest', function () {
|
||||
var counters = sharp.counters();
|
||||
const counters = sharp.counters();
|
||||
assert.strictEqual(0, counters.queue);
|
||||
assert.strictEqual(0, counters.process);
|
||||
});
|
||||
@ -81,15 +79,15 @@ describe('Utilities', function() {
|
||||
|
||||
describe('SIMD', function () {
|
||||
it('Can get current state', function () {
|
||||
var simd = sharp.simd();
|
||||
const simd = sharp.simd();
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
it('Can disable', function () {
|
||||
var simd = sharp.simd(false);
|
||||
const simd = sharp.simd(false);
|
||||
assert.strictEqual(simd, false);
|
||||
});
|
||||
it('Can attempt to enable', function () {
|
||||
var simd = sharp.simd(true);
|
||||
const simd = sharp.simd(true);
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
});
|
||||
@ -128,5 +126,4 @@ describe('Utilities', function() {
|
||||
assert.strictEqual('string', typeof sharp.versions.vips);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user