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:
|
machine:
|
||||||
|
node:
|
||||||
|
version: v4.6.1
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
test:
|
test:
|
||||||
|
@ -87,9 +87,6 @@
|
|||||||
"semistandard": {
|
"semistandard": {
|
||||||
"env": [
|
"env": [
|
||||||
"mocha"
|
"mocha"
|
||||||
],
|
|
||||||
"ignore": [
|
|
||||||
"test"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,24 @@
|
|||||||
|
|
||||||
process.env.UV_THREADPOOL_SIZE = 64;
|
process.env.UV_THREADPOOL_SIZE = 64;
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var async = require('async');
|
const async = require('async');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
var width = 720;
|
const width = 720;
|
||||||
var height = 480;
|
const height = 480;
|
||||||
|
|
||||||
sharp.concurrency(1);
|
sharp.concurrency(1);
|
||||||
sharp.simd(true);
|
sharp.simd(true);
|
||||||
|
|
||||||
var timer = setInterval(function() {
|
const timer = setInterval(function () {
|
||||||
console.dir(sharp.counters());
|
console.dir(sharp.counters());
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
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,
|
async.times(parallelism,
|
||||||
function (id, callback) {
|
function (id, callback) {
|
||||||
/* jslint unused: false */
|
/* jslint unused: false */
|
||||||
@ -31,7 +31,7 @@ async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function(parallelism, next) {
|
|||||||
function (err, ids) {
|
function (err, ids) {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
assert(ids.length === parallelism);
|
assert(ids.length === parallelism);
|
||||||
var mean = ids.reduce(function(a, b) {
|
const mean = ids.reduce(function (a, b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
}) / ids.length;
|
}) / ids.length;
|
||||||
console.log(parallelism + ' parallel calls: fastest=' + ids[0] + 'ms slowest=' + ids[ids.length - 1] + 'ms mean=' + mean + 'ms');
|
console.log(parallelism + ' parallel calls: fastest=' + ids[0] + 'ms slowest=' + ids[ids.length - 1] + 'ms mean=' + mean + 'ms');
|
||||||
|
@ -1,34 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var async = require('async');
|
const async = require('async');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var Benchmark = require('benchmark');
|
const Benchmark = require('benchmark');
|
||||||
var semver = require('semver');
|
|
||||||
|
|
||||||
// Contenders
|
// Contenders
|
||||||
var gm = require('gm');
|
const gm = require('gm');
|
||||||
var imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
var jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
var sharp = require('../../');
|
const sharp = require('../../');
|
||||||
var imagemagickNative;
|
let imagemagickNative;
|
||||||
try {
|
try {
|
||||||
imagemagickNative = require('imagemagick-native');
|
imagemagickNative = require('imagemagick-native');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Excluding imagemagick-native');
|
console.log('Excluding imagemagick-native');
|
||||||
}
|
}
|
||||||
var lwip;
|
let lwip;
|
||||||
try {
|
try {
|
||||||
lwip = require('lwip');
|
lwip = require('lwip');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Excluding lwip');
|
console.log('Excluding lwip');
|
||||||
}
|
}
|
||||||
|
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
var width = 720;
|
const width = 720;
|
||||||
var height = 480;
|
const height = 480;
|
||||||
|
|
||||||
// Disable libvips cache to ensure tests are as fair as they can be
|
// Disable libvips cache to ensure tests are as fair as they can be
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
@ -37,17 +36,17 @@ sharp.simd(true);
|
|||||||
|
|
||||||
async.series({
|
async.series({
|
||||||
'jpeg': function (callback) {
|
'jpeg': function (callback) {
|
||||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
var jpegSuite = new Benchmark.Suite('jpeg');
|
const jpegSuite = new Benchmark.Suite('jpeg');
|
||||||
// jimp
|
// jimp
|
||||||
jpegSuite.add('jimp-buffer-buffer', {
|
jpegSuite.add('jimp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
new jimp(inputJpgBuffer, function(err) {
|
jimp.read(inputJpgBuffer, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
this
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.getBuffer(jimp.MIME_JPEG, function (err) {
|
.getBuffer(jimp.MIME_JPEG, function (err) {
|
||||||
@ -63,11 +62,11 @@ async.series({
|
|||||||
}).add('jimp-file-file', {
|
}).add('jimp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
new jimp(fixtures.inputJpg, function(err) {
|
jimp.read(fixtures.inputJpg, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
this
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(fixtures.outputJpg, function (err) {
|
||||||
@ -278,12 +277,12 @@ async.series({
|
|||||||
}).add('sharp-stream-stream', {
|
}).add('sharp-stream-stream', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
writable.on('finish', function () {
|
writable.on('finish', function () {
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
var pipeline = sharp()
|
const pipeline = sharp()
|
||||||
.resize(width, height);
|
.resize(width, height);
|
||||||
readable.pipe(pipeline).pipe(writable);
|
readable.pipe(pipeline).pipe(writable);
|
||||||
}
|
}
|
||||||
@ -320,8 +319,8 @@ async.series({
|
|||||||
},
|
},
|
||||||
// Effect of applying operations
|
// Effect of applying operations
|
||||||
operations: function (callback) {
|
operations: function (callback) {
|
||||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
var operationsSuite = new Benchmark.Suite('operations');
|
const operationsSuite = new Benchmark.Suite('operations');
|
||||||
operationsSuite.add('sharp-sharpen-mild', {
|
operationsSuite.add('sharp-sharpen-mild', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
@ -557,7 +556,7 @@ async.series({
|
|||||||
},
|
},
|
||||||
// Comparitive speed of kernels
|
// Comparitive speed of kernels
|
||||||
kernels: function (callback) {
|
kernels: function (callback) {
|
||||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
@ -608,17 +607,17 @@ async.series({
|
|||||||
},
|
},
|
||||||
// PNG
|
// PNG
|
||||||
png: function (callback) {
|
png: function (callback) {
|
||||||
var inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||||
var pngSuite = new Benchmark.Suite('png');
|
const pngSuite = new Benchmark.Suite('png');
|
||||||
// jimp
|
// jimp
|
||||||
pngSuite.add('jimp-buffer-buffer', {
|
pngSuite.add('jimp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
new jimp(inputPngBuffer, function(err) {
|
jimp.read(inputPngBuffer, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
this
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.getBuffer(jimp.MIME_PNG, function (err) {
|
.getBuffer(jimp.MIME_PNG, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -633,11 +632,11 @@ async.series({
|
|||||||
}).add('jimp-file-file', {
|
}).add('jimp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
new jimp(fixtures.inputPng, function(err) {
|
jimp.read(fixtures.inputPng, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
this
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.write(fixtures.outputPng, function (err) {
|
.write(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -835,7 +834,7 @@ async.series({
|
|||||||
},
|
},
|
||||||
// WebP
|
// WebP
|
||||||
webp: function (callback) {
|
webp: function (callback) {
|
||||||
var inputWebPBuffer = fs.readFileSync(fixtures.inputWebP);
|
const inputWebPBuffer = fs.readFileSync(fixtures.inputWebP);
|
||||||
(new Benchmark.Suite('webp')).add('sharp-buffer-file', {
|
(new Benchmark.Suite('webp')).add('sharp-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
var gm = require('gm');
|
const gm = require('gm');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var Benchmark = require('benchmark');
|
const Benchmark = require('benchmark');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
sharp.simd(true);
|
sharp.simd(true);
|
||||||
|
|
||||||
var min = 320;
|
const min = 320;
|
||||||
var max = 960;
|
const max = 960;
|
||||||
|
|
||||||
var randomDimension = function() {
|
const randomDimension = function () {
|
||||||
return Math.ceil(Math.random() * (max - min) + min);
|
return Math.ceil(Math.random() * (max - min) + min);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,6 +70,6 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
}).on('cycle', function (event) {
|
}).on('cycle', function (event) {
|
||||||
console.log(String(event.target));
|
console.log(String(event.target));
|
||||||
}).on('complete', function () {
|
}).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);
|
assert.strictEqual('sharp', String(winner), 'sharp was slower than ' + winner);
|
||||||
}).run();
|
}).run();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*jshint esversion: 6 */
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
@ -21,8 +20,7 @@ const fetchImages = function(offset) {
|
|||||||
response.posts.forEach((post) => {
|
response.posts.forEach((post) => {
|
||||||
const url = post.photos[0].alt_sizes
|
const url = post.photos[0].alt_sizes
|
||||||
.filter((image) => image.width === 100)
|
.filter((image) => image.width === 100)
|
||||||
.map((image) => image.url)
|
.map((image) => image.url)[0];
|
||||||
[0];
|
|
||||||
const filename = `./images/${post.id}.jpg`;
|
const filename = `./images/${post.id}.jpg`;
|
||||||
try {
|
try {
|
||||||
fs.statSync(filename);
|
fs.statSync(filename);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*jshint esversion: 6 */
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const child_process = require('child_process');
|
const childProcess = require('child_process');
|
||||||
|
|
||||||
const a = [];
|
const a = [];
|
||||||
const b = [];
|
const b = [];
|
||||||
@ -12,7 +11,7 @@ fs.readdirSync('./images')
|
|||||||
.forEach((file) => {
|
.forEach((file) => {
|
||||||
// Extract one pixel, avoiding first DCT block, and return value of A and B channels
|
// 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 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(' ');
|
const ab = result.split(' ');
|
||||||
a.push(ab[0]);
|
a.push(ab[0]);
|
||||||
b.push(ab[1]);
|
b.push(ab[1]);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*jshint esversion: 6 */
|
|
||||||
|
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const fs = require('fs');
|
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) {
|
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);
|
const accuracy = Math.round(Math.abs(userData[file].left - info.cropCalcLeft) / (metadata.width - salientWidth) * 100);
|
||||||
incrementScore(accuracy, crop);
|
incrementScore(accuracy, crop);
|
||||||
done();
|
done(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// Top edge accuracy
|
// 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) {
|
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);
|
const accuracy = Math.round(Math.abs(userData[file].top - info.cropCalcTop) / (metadata.height - salientHeight) * 100);
|
||||||
incrementScore(accuracy, crop);
|
incrementScore(accuracy, crop);
|
||||||
done();
|
done(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], done);
|
], done);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*jshint esversion: 6, loopfunc: true */
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -39,7 +38,10 @@ fs.readdirSync(userDataDir).forEach(function(file) {
|
|||||||
const regions = lines[linePos].split('; ');
|
const regions = lines[linePos].split('; ');
|
||||||
linePos = linePos + 2;
|
linePos = linePos + 2;
|
||||||
// Parse human-labelled regions for min/max coords
|
// 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) {
|
regions.forEach(function (region) {
|
||||||
if (region.indexOf(' ') !== -1) {
|
if (region.indexOf(' ') !== -1) {
|
||||||
const coords = region.split(' ');
|
const coords = region.split(' ');
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
|
|
||||||
describe('Alpha transparency', function () {
|
describe('Alpha transparency', function () {
|
||||||
|
|
||||||
it('Flatten to black', function (done) {
|
it('Flatten to black', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten()
|
.flatten()
|
||||||
@ -45,7 +44,7 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten 16-bit PNG with transparency to orange', function (done) {
|
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)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.flatten()
|
.flatten()
|
||||||
.background({r: 255, g: 102, b: 0})
|
.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) {
|
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
||||||
var BASE_NAME = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||||
var actual = fixtures.path('output.' + BASE_NAME);
|
const actual = fixtures.path('output.' + base);
|
||||||
var expected = fixtures.expected(BASE_NAME);
|
const expected = fixtures.expected(base);
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.resize(2048, 1536)
|
.resize(2048, 1536)
|
||||||
.toFile(actual, function (err) {
|
.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) {
|
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
||||||
var BASE_NAME = 'alpha-premultiply-reduction-1024x768-paper.png';
|
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||||
var actual = fixtures.path('output.' + BASE_NAME);
|
const actual = fixtures.path('output.' + base);
|
||||||
var expected = fixtures.expected(BASE_NAME);
|
const expected = fixtures.expected(base);
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.resize(1024, 768)
|
.resize(1024, 768)
|
||||||
.toFile(actual, function (err) {
|
.toFile(actual, function (err) {
|
||||||
@ -113,5 +112,4 @@ describe('Alpha transparency', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
|
|
||||||
describe('Bandbool per-channel boolean operations', function () {
|
describe('Bandbool per-channel boolean operations', function () {
|
||||||
|
|
||||||
[
|
[
|
||||||
sharp.bool.and,
|
sharp.bool.and,
|
||||||
sharp.bool.or,
|
sharp.bool.or,
|
||||||
@ -30,6 +29,7 @@ describe('Bandbool per-channel boolean operations', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.bandbool('and')
|
.bandbool('and')
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Blur', function () {
|
describe('Blur', function () {
|
||||||
|
|
||||||
it('specific radius 1', function (done) {
|
it('specific radius 1', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(1)
|
.blur(1)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -24,6 +24,7 @@ describe('Blur', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(10)
|
.blur(10)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -36,6 +37,7 @@ describe('Blur', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(0.3)
|
.blur(0.3)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -48,6 +50,7 @@ describe('Blur', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur()
|
.blur()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -66,6 +69,7 @@ describe('Blur', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(false)
|
.blur(false)
|
||||||
.toBuffer(function (err, notBlurred, info) {
|
.toBuffer(function (err, notBlurred, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual(true, notBlurred.length > 0);
|
assert.strictEqual(true, notBlurred.length > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -74,6 +78,7 @@ describe('Blur', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(true)
|
.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 > 0);
|
||||||
assert.strictEqual(true, blurred.length < notBlurred.length);
|
assert.strictEqual(true, blurred.length < notBlurred.length);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -83,5 +88,4 @@ describe('Blur', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
|
||||||
var sharp = require('../../index');
|
const fixtures = require('../fixtures');
|
||||||
|
const sharp = require('../../index');
|
||||||
|
|
||||||
describe('Boolean operation between two images', function () {
|
describe('Boolean operation between two images', function () {
|
||||||
|
const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||||
var inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
|
||||||
|
|
||||||
[
|
[
|
||||||
sharp.bool.and,
|
sharp.bool.and,
|
||||||
@ -15,7 +15,6 @@ describe('Boolean operation between two images', function() {
|
|||||||
sharp.bool.eor
|
sharp.bool.eor
|
||||||
]
|
]
|
||||||
.forEach(function (op) {
|
.forEach(function (op) {
|
||||||
|
|
||||||
it(op + ' operation, file', function (done) {
|
it(op + ' operation, file', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -56,7 +55,6 @@ describe('Boolean operation between two images', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid operation', function () {
|
it('Invalid operation', function () {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
|
|
||||||
// Define SHARP_TEST_WITHOUT_CACHE environment variable to prevent use of libvips' cache
|
// Define SHARP_TEST_WITHOUT_CACHE environment variable to prevent use of libvips' cache
|
||||||
|
|
||||||
beforeEach(function () {
|
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';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Clone', function () {
|
describe('Clone', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
});
|
});
|
||||||
@ -16,10 +15,10 @@ describe('Clone', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to multiple Streams', function (done) {
|
it('Read from Stream and write to multiple Streams', function (done) {
|
||||||
var finishEventsExpected = 2;
|
let finishEventsExpected = 2;
|
||||||
// Output stream 1
|
// Output stream 1
|
||||||
var output1 = fixtures.path('output.multi-stream.1.jpg');
|
const output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||||
var writable1 = fs.createWriteStream(output1);
|
const writable1 = fs.createWriteStream(output1);
|
||||||
writable1.on('finish', function () {
|
writable1.on('finish', function () {
|
||||||
sharp(output1).toBuffer(function (err, data, info) {
|
sharp(output1).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -36,8 +35,8 @@ describe('Clone', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Output stream 2
|
// Output stream 2
|
||||||
var output2 = fixtures.path('output.multi-stream.2.jpg');
|
const output2 = fixtures.path('output.multi-stream.2.jpg');
|
||||||
var writable2 = fs.createWriteStream(output2);
|
const writable2 = fs.createWriteStream(output2);
|
||||||
writable2.on('finish', function () {
|
writable2.on('finish', function () {
|
||||||
sharp(output2).toBuffer(function (err, data, info) {
|
sharp(output2).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -54,12 +53,11 @@ describe('Clone', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Create parent instance
|
// Create parent instance
|
||||||
var rotator = sharp().rotate(90);
|
const rotator = sharp().rotate(90);
|
||||||
// Cloned instances with differing dimensions
|
// Cloned instances with differing dimensions
|
||||||
rotator.clone().resize(320, 240).pipe(writable1);
|
rotator.clone().resize(320, 240).pipe(writable1);
|
||||||
rotator.clone().resize(100, 122).pipe(writable2);
|
rotator.clone().resize(100, 122).pipe(writable2);
|
||||||
// Go
|
// Go
|
||||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Colour space conversion', function () {
|
describe('Colour space conversion', function () {
|
||||||
|
|
||||||
it('To greyscale', function (done) {
|
it('To greyscale', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Convolve', function () {
|
describe('Convolve', function () {
|
||||||
|
|
||||||
it('specific convolution kernel 1', function (done) {
|
it('specific convolution kernel 1', function (done) {
|
||||||
sharp(fixtures.inputPngStripesV)
|
sharp(fixtures.inputPngStripesV)
|
||||||
.convolve({
|
.convolve({
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var cpplint = require('node-cpplint/lib/');
|
const cpplint = require('node-cpplint/lib/');
|
||||||
|
|
||||||
describe('cpplint', function () {
|
describe('cpplint', function () {
|
||||||
|
|
||||||
// Ignore cpplint failures, possibly newline-related, on Windows
|
// Ignore cpplint failures, possibly newline-related, on Windows
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
// List C++ source files
|
// 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';
|
return source !== 'libvips';
|
||||||
}).forEach(function (source) {
|
}).forEach(function (source) {
|
||||||
var file = path.join('src', source);
|
const file = path.join('src', source);
|
||||||
it(file, function (done) {
|
it(file, function (done) {
|
||||||
// Lint each source file
|
// Lint each source file
|
||||||
cpplint({
|
cpplint({
|
||||||
@ -38,14 +37,12 @@ describe('cpplint', function() {
|
|||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
var expected = {};
|
const expected = {};
|
||||||
expected[file] = [];
|
expected[file] = [];
|
||||||
assert.deepEqual(expected, report);
|
assert.deepEqual(expected, report);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Crop', function () {
|
describe('Crop', function () {
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name: 'North',
|
name: 'North',
|
||||||
@ -161,7 +160,6 @@ describe('Crop', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Entropy-based strategy', function () {
|
describe('Entropy-based strategy', function () {
|
||||||
|
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
@ -193,11 +191,9 @@ describe('Crop', function() {
|
|||||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Attention strategy', function () {
|
describe('Attention strategy', function () {
|
||||||
|
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
@ -229,6 +225,5 @@ describe('Crop', function() {
|
|||||||
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Embed', function () {
|
describe('Embed', function () {
|
||||||
|
|
||||||
it('JPEG within PNG, no alpha channel', function (done) {
|
it('JPEG within PNG, no alpha channel', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.embed()
|
.embed()
|
||||||
@ -118,5 +117,4 @@ describe('Embed', function() {
|
|||||||
fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done);
|
fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Extend', function () {
|
describe('Extend', function () {
|
||||||
|
|
||||||
it('extend all sides equally with RGB', function (done) {
|
it('extend all sides equally with RGB', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
@ -55,10 +54,10 @@ describe('Extend', function () {
|
|||||||
.toFormat(sharp.format.png)
|
.toFormat(sharp.format.png)
|
||||||
.extend({top: 0, bottom: 10, left: 0, right: 10})
|
.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(610, info.width);
|
||||||
assert.strictEqual(460, info.height);
|
assert.strictEqual(460, info.height);
|
||||||
fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done);
|
fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Partial image extraction', function () {
|
describe('Partial image extraction', function () {
|
||||||
|
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
.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 })
|
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
assert(err instanceof Error);
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Image channel extraction', function () {
|
describe('Image channel extraction', function () {
|
||||||
|
|
||||||
it('Red channel', function (done) {
|
it('Red channel', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('red')
|
.extractChannel('red')
|
||||||
@ -77,5 +76,4 @@ describe('Image channel extraction', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Test fixtures', function () {
|
describe('Test fixtures', function () {
|
||||||
describe('assertMaxColourDistance', 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 () {
|
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);
|
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 () {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Gamma correction', function () {
|
describe('Gamma correction', function () {
|
||||||
|
|
||||||
it('value of 0.0 (disabled)', function (done) {
|
it('value of 0.0 (disabled)', function (done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(129, info.width);
|
assert.strictEqual(129, info.width);
|
||||||
assert.strictEqual(111, info.height);
|
assert.strictEqual(111, info.height);
|
||||||
@ -23,6 +23,7 @@ describe('Gamma correction', function() {
|
|||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.gamma()
|
.gamma()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(129, info.width);
|
assert.strictEqual(129, info.width);
|
||||||
assert.strictEqual(111, info.height);
|
assert.strictEqual(111, info.height);
|
||||||
@ -35,6 +36,7 @@ describe('Gamma correction', function() {
|
|||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.gamma(3)
|
.gamma(3)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(129, info.width);
|
assert.strictEqual(129, info.width);
|
||||||
assert.strictEqual(111, info.height);
|
assert.strictEqual(111, info.height);
|
||||||
@ -47,6 +49,7 @@ describe('Gamma correction', function() {
|
|||||||
.resize(320)
|
.resize(320)
|
||||||
.gamma()
|
.gamma()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, { threshold: 11 }, done);
|
fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, { threshold: 11 }, done);
|
||||||
@ -58,5 +61,4 @@ describe('Gamma correction', function() {
|
|||||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Interpolators and kernels', function () {
|
describe('Interpolators and kernels', function () {
|
||||||
|
|
||||||
describe('Reducers', function () {
|
describe('Reducers', function () {
|
||||||
[
|
[
|
||||||
sharp.kernel.cubic,
|
sharp.kernel.cubic,
|
||||||
@ -59,5 +58,4 @@ describe('Interpolators and kernels', function() {
|
|||||||
sharp().resize(null, null, { interpolator: 'unknown' });
|
sharp().resize(null, null, { interpolator: 'unknown' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
100
test/unit/io.js
100
test/unit/io.js
@ -1,13 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Input/output', function () {
|
describe('Input/output', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
});
|
});
|
||||||
@ -16,7 +15,7 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from File and write to Stream', function (done) {
|
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 () {
|
writable.on('finish', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -33,8 +32,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Buffer and write to Stream', function (done) {
|
it('Read from Buffer and write to Stream', function (done) {
|
||||||
var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
writable.on('finish', function () {
|
writable.on('finish', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -51,8 +50,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to File', function (done) {
|
it('Read from Stream and write to File', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function(err, info) {
|
const pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -65,8 +64,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to Buffer', function (done) {
|
it('Read from Stream and write to Buffer', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var pipeline = sharp().resize(320, 240).toBuffer(function(err, data, info) {
|
const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
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) {
|
it('Read from Stream and write to Buffer via Promise', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var pipeline = sharp().resize(1, 1);
|
const pipeline = sharp().resize(1, 1);
|
||||||
pipeline.toBuffer().then(function (data) {
|
pipeline.toBuffer().then(function (data) {
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
done();
|
done();
|
||||||
@ -91,8 +90,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to Stream', function (done) {
|
it('Read from Stream and write to Stream', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
writable.on('finish', function () {
|
writable.on('finish', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -105,15 +104,15 @@ describe('Input/output', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
readable.pipe(pipeline).pipe(writable);
|
readable.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream should emit info event', function (done) {
|
it('Stream should emit info event', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
var pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
var infoEventEmitted = false;
|
let infoEventEmitted = false;
|
||||||
pipeline.on('info', function (info) {
|
pipeline.on('info', function (info) {
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -130,8 +129,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Handle Stream to Stream error ', function (done) {
|
it('Handle Stream to Stream error ', function (done) {
|
||||||
var pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
var anErrorWasEmitted = false;
|
let anErrorWasEmitted = false;
|
||||||
pipeline.on('error', function (err) {
|
pipeline.on('error', function (err) {
|
||||||
anErrorWasEmitted = !!err;
|
anErrorWasEmitted = !!err;
|
||||||
}).on('end', function () {
|
}).on('end', function () {
|
||||||
@ -139,14 +138,14 @@ describe('Input/output', function() {
|
|||||||
fs.unlinkSync(fixtures.outputJpg);
|
fs.unlinkSync(fixtures.outputJpg);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
var readableButNotAnImage = fs.createReadStream(__filename);
|
const readableButNotAnImage = fs.createReadStream(__filename);
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handle File to Stream error', function (done) {
|
it('Handle File to Stream error', function (done) {
|
||||||
var readableButNotAnImage = sharp(__filename).resize(320, 240);
|
const readableButNotAnImage = sharp(__filename).resize(320, 240);
|
||||||
var anErrorWasEmitted = false;
|
let anErrorWasEmitted = false;
|
||||||
readableButNotAnImage.on('error', function (err) {
|
readableButNotAnImage.on('error', function (err) {
|
||||||
anErrorWasEmitted = !!err;
|
anErrorWasEmitted = !!err;
|
||||||
}).on('end', function () {
|
}).on('end', function () {
|
||||||
@ -154,7 +153,7 @@ describe('Input/output', function() {
|
|||||||
fs.unlinkSync(fixtures.outputJpg);
|
fs.unlinkSync(fixtures.outputJpg);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(fixtures.outputJpg);
|
||||||
readableButNotAnImage.pipe(writable);
|
readableButNotAnImage.pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -387,7 +386,7 @@ describe('Input/output', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('Invalid output format', function (done) {
|
it('Invalid output format', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().toFormat('zoinks');
|
sharp().toFormat('zoinks');
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -413,7 +412,6 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Output filename with unknown extension', function () {
|
describe('Output filename with unknown extension', function () {
|
||||||
|
|
||||||
it('Match JPEG input', function (done) {
|
it('Match JPEG input', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
@ -500,9 +498,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('PNG output', function () {
|
describe('PNG output', function () {
|
||||||
|
|
||||||
it('compression level is valid', function (done) {
|
it('compression level is valid', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().compressionLevel(0);
|
sharp().compressionLevel(0);
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -512,7 +509,7 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('compression level is invalid', function (done) {
|
it('compression level is invalid', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().compressionLevel(-1);
|
sharp().compressionLevel(-1);
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -662,7 +659,7 @@ describe('Input/output', function() {
|
|||||||
assert.strictEqual(320, withInfo.width);
|
assert.strictEqual(320, withInfo.width);
|
||||||
assert.strictEqual(240, withInfo.height);
|
assert.strictEqual(240, withInfo.height);
|
||||||
// Verify image is of a different size (progressive output even without mozjpeg)
|
// 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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -725,7 +722,7 @@ describe('Input/output', function() {
|
|||||||
|
|
||||||
if (sharp.format.tiff.input.buffer) {
|
if (sharp.format.tiff.input.buffer) {
|
||||||
it('Load TIFF from Buffer', function (done) {
|
it('Load TIFF from Buffer', function (done) {
|
||||||
var inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||||
sharp(inputTiffBuffer)
|
sharp(inputTiffBuffer)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -743,7 +740,7 @@ describe('Input/output', function() {
|
|||||||
|
|
||||||
if (sharp.format.gif.input.buffer) {
|
if (sharp.format.gif.input.buffer) {
|
||||||
it('Load GIF from Buffer', function (done) {
|
it('Load GIF from Buffer', function (done) {
|
||||||
var inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
const inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
||||||
sharp(inputGifBuffer)
|
sharp(inputGifBuffer)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -778,7 +775,7 @@ describe('Input/output', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.v.input.file) {
|
if (sharp.format.v.input.file) {
|
||||||
it("Load Vips V file", function(done) {
|
it('Load Vips V file', function (done) {
|
||||||
sharp(fixtures.inputV)
|
sharp(fixtures.inputV)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -793,7 +790,7 @@ describe('Input/output', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.v.output.file) {
|
if (sharp.format.v.output.file) {
|
||||||
it("Save Vips V file", function(done) {
|
it('Save Vips V file', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({left: 910, top: 1105, width: 70, height: 60})
|
.extract({left: 910, top: 1105, width: 70, height: 60})
|
||||||
.toFile(fixtures.outputV, function (err, info) {
|
.toFile(fixtures.outputV, function (err, info) {
|
||||||
@ -816,6 +813,7 @@ describe('Input/output', function() {
|
|||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual(32 * 24 * 1, info.size);
|
assert.strictEqual(32 * 24 * 1, info.size);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('raw', info.format);
|
assert.strictEqual('raw', info.format);
|
||||||
@ -829,6 +827,7 @@ describe('Input/output', function() {
|
|||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.toFormat('raw')
|
.toFormat('raw')
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual(32 * 24 * 3, info.size);
|
assert.strictEqual(32 * 24 * 3, info.size);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('raw', info.format);
|
assert.strictEqual('raw', info.format);
|
||||||
@ -842,6 +841,7 @@ describe('Input/output', function() {
|
|||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.toFormat(sharp.format.raw)
|
.toFormat(sharp.format.raw)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual(32 * 24 * 4, info.size);
|
assert.strictEqual(32 * 24 * 4, info.size);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('raw', info.format);
|
assert.strictEqual('raw', info.format);
|
||||||
@ -854,9 +854,8 @@ describe('Input/output', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('Limit pixel count of input image', function () {
|
describe('Limit pixel count of input image', function () {
|
||||||
|
|
||||||
it('Invalid fails - negative', function (done) {
|
it('Invalid fails - negative', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().limitInputPixels(-1);
|
sharp().limitInputPixels(-1);
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -866,7 +865,7 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid fails - float', function (done) {
|
it('Invalid fails - float', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().limitInputPixels(12.3);
|
sharp().limitInputPixels(12.3);
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -876,7 +875,7 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid fails - string', function (done) {
|
it('Invalid fails - string', function (done) {
|
||||||
var isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().limitInputPixels('fail');
|
sharp().limitInputPixels('fail');
|
||||||
isValid = true;
|
isValid = true;
|
||||||
@ -927,7 +926,6 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Input options', function () {
|
describe('Input options', function () {
|
||||||
@ -1034,8 +1032,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Queue length change events', function (done) {
|
it('Queue length change events', function (done) {
|
||||||
var eventCounter = 0;
|
let eventCounter = 0;
|
||||||
var queueListener = function(queueLength) {
|
const queueListener = function (queueLength) {
|
||||||
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
||||||
eventCounter++;
|
eventCounter++;
|
||||||
};
|
};
|
||||||
@ -1053,8 +1051,8 @@ describe('Input/output', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Info event data', function (done) {
|
it('Info event data', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJPGBig);
|
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||||
var inPipeline = sharp()
|
const inPipeline = sharp()
|
||||||
.resize(840, 472)
|
.resize(840, 472)
|
||||||
.raw()
|
.raw()
|
||||||
.on('info', function (info) {
|
.on('info', function (info) {
|
||||||
@ -1062,20 +1060,16 @@ describe('Input/output', function() {
|
|||||||
assert.strictEqual(472, info.height);
|
assert.strictEqual(472, info.height);
|
||||||
assert.strictEqual(3, info.channels);
|
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')
|
.toFormat('jpeg')
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
||||||
readable = fs.createReadStream(fixtures.inputJPGBig);
|
const goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}})
|
||||||
var goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}})
|
|
||||||
.toFormat('jpeg')
|
.toFormat('jpeg')
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
inPipeline = sharp()
|
|
||||||
.resize(840, 472)
|
|
||||||
.raw();
|
|
||||||
readable.pipe(inPipeline).pipe(goodPipeline);
|
readable.pipe(inPipeline).pipe(goodPipeline);
|
||||||
});
|
});
|
||||||
readable.pipe(inPipeline).pipe(badPipeline);
|
readable.pipe(inPipeline).pipe(badPipeline);
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var exifReader = require('exif-reader');
|
const exifReader = require('exif-reader');
|
||||||
var icc = require('icc');
|
const icc = require('icc');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Image metadata', function () {
|
describe('Image metadata', function () {
|
||||||
|
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -43,14 +42,14 @@ describe('Image metadata', function() {
|
|||||||
// EXIF
|
// EXIF
|
||||||
assert.strictEqual('object', typeof metadata.exif);
|
assert.strictEqual('object', typeof metadata.exif);
|
||||||
assert.strictEqual(true, metadata.exif instanceof Buffer);
|
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);
|
||||||
assert.strictEqual('object', typeof exif.image);
|
assert.strictEqual('object', typeof exif.image);
|
||||||
assert.strictEqual('number', typeof exif.image.XResolution);
|
assert.strictEqual('number', typeof exif.image.XResolution);
|
||||||
// ICC
|
// ICC
|
||||||
assert.strictEqual('object', typeof metadata.icc);
|
assert.strictEqual('object', typeof metadata.icc);
|
||||||
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
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('object', typeof profile);
|
||||||
assert.strictEqual('Generic RGB Profile', profile.description);
|
assert.strictEqual('Generic RGB Profile', profile.description);
|
||||||
done();
|
done();
|
||||||
@ -215,8 +214,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Stream in, Promise out', function (done) {
|
it('Stream in, Promise out', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var pipeline = sharp();
|
const pipeline = sharp();
|
||||||
pipeline.metadata().then(function (metadata) {
|
pipeline.metadata().then(function (metadata) {
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual(2725, metadata.width);
|
assert.strictEqual(2725, metadata.width);
|
||||||
@ -237,8 +236,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Stream', function (done) {
|
it('Stream', function (done) {
|
||||||
var readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
var pipeline = sharp().metadata(function(err, metadata) {
|
const pipeline = sharp().metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual(2725, metadata.width);
|
assert.strictEqual(2725, metadata.width);
|
||||||
@ -257,7 +256,7 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Resize to half width using metadata', function (done) {
|
it('Resize to half width using metadata', function (done) {
|
||||||
var image = sharp(fixtures.inputJpg);
|
const image = sharp(fixtures.inputJpg);
|
||||||
image.metadata(function (err, metadata) {
|
image.metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
@ -294,14 +293,14 @@ describe('Image metadata', function() {
|
|||||||
assert.strictEqual('object', typeof metadata.exif);
|
assert.strictEqual('object', typeof metadata.exif);
|
||||||
assert.strictEqual(true, metadata.exif instanceof Buffer);
|
assert.strictEqual(true, metadata.exif instanceof Buffer);
|
||||||
// EXIF
|
// EXIF
|
||||||
var exif = exifReader(metadata.exif);
|
const exif = exifReader(metadata.exif);
|
||||||
assert.strictEqual('object', typeof exif);
|
assert.strictEqual('object', typeof exif);
|
||||||
assert.strictEqual('object', typeof exif.image);
|
assert.strictEqual('object', typeof exif.image);
|
||||||
assert.strictEqual('number', typeof exif.image.XResolution);
|
assert.strictEqual('number', typeof exif.image.XResolution);
|
||||||
// ICC
|
// ICC
|
||||||
assert.strictEqual('object', typeof metadata.icc);
|
assert.strictEqual('object', typeof metadata.icc);
|
||||||
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
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('object', typeof profile);
|
||||||
assert.strictEqual('RGB', profile.colorSpace);
|
assert.strictEqual('RGB', profile.colorSpace);
|
||||||
assert.strictEqual('Perceptual', profile.intent);
|
assert.strictEqual('Perceptual', profile.intent);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Negate', function () {
|
describe('Negate', function () {
|
||||||
it('negate (jpeg)', function (done) {
|
it('negate (jpeg)', function (done) {
|
||||||
@ -11,6 +11,7 @@ describe('Negate', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -23,6 +24,7 @@ describe('Negate', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -35,6 +37,7 @@ describe('Negate', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -47,6 +50,7 @@ describe('Negate', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -54,12 +58,12 @@ describe('Negate', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.output.file) {
|
|
||||||
it('negate (webp)', function (done) {
|
it('negate (webp)', function (done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -72,19 +76,20 @@ describe('Negate', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done);
|
fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
it('negate (true)', function (done) {
|
it('negate (true)', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate(true)
|
.negate(true)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -93,11 +98,11 @@ describe('Negate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('negate (false)', function (done) {
|
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)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.negate(false)
|
.negate(false)
|
||||||
.toFile(output, function (err, info) {
|
.toFile(output, function (err, info) {
|
||||||
if (err) done(err);
|
if (err) throw err;
|
||||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
var assertNormalized = function(data) {
|
const assertNormalized = function (data) {
|
||||||
var min = 255;
|
let min = 255;
|
||||||
var max = 0;
|
let max = 0;
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
min = Math.min(min, data[i]);
|
min = Math.min(min, data[i]);
|
||||||
max = Math.max(max, data[i]);
|
max = Math.max(max, data[i]);
|
||||||
}
|
}
|
||||||
@ -17,7 +17,6 @@ var assertNormalized = function(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('Normalization', function () {
|
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);
|
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) {
|
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)
|
sharp(fixtures.inputPngWithOneColor)
|
||||||
.normalize()
|
.normalize()
|
||||||
.toFile(output, function (err, info) {
|
.toFile(output, function (err, info) {
|
||||||
@ -108,5 +107,4 @@ describe('Normalization', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
|
||||||
var sharp = require('../../index');
|
const fixtures = require('../fixtures');
|
||||||
|
const sharp = require('../../index');
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
var getPaths = function(baseName, extension) {
|
const getPaths = function (baseName, extension) {
|
||||||
if (typeof extension === 'undefined') {
|
if (typeof extension === 'undefined') {
|
||||||
extension = 'png';
|
extension = 'png';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
actual: fixtures.path('output.' + baseName + '.' + extension),
|
actual: fixtures.path('output.' + baseName + '.' + extension),
|
||||||
expected: fixtures.expected(baseName + '.' + extension),
|
expected: fixtures.expected(baseName + '.' + extension)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
describe('Overlays', function () {
|
describe('Overlays', function () {
|
||||||
it('Overlay transparent PNG file on solid background', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer0)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||||
@ -31,7 +32,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay transparent PNG Buffer on solid background', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer0)
|
||||||
.overlayWith(fs.readFileSync(fixtures.inputPngOverlayLayer1))
|
.overlayWith(fs.readFileSync(fixtures.inputPngOverlayLayer1))
|
||||||
@ -43,7 +44,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay low-alpha transparent PNG on solid background', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer0)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||||
@ -55,7 +56,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite three transparent PNGs into one', function (done) {
|
it('Composite three transparent PNGs into one', function (done) {
|
||||||
var paths = getPaths('alpha-layer-012');
|
const paths = getPaths('alpha-layer-012');
|
||||||
|
|
||||||
sharp(fixtures.inputPngOverlayLayer0)
|
sharp(fixtures.inputPngOverlayLayer0)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||||
@ -72,7 +73,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite two transparent PNGs into one', function (done) {
|
it('Composite two transparent PNGs into one', function (done) {
|
||||||
var paths = getPaths('alpha-layer-12');
|
const paths = getPaths('alpha-layer-12');
|
||||||
|
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer2)
|
.overlayWith(fixtures.inputPngOverlayLayer2)
|
||||||
@ -84,7 +85,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite two low-alpha transparent PNGs into one', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer2LowAlpha)
|
.overlayWith(fixtures.inputPngOverlayLayer2LowAlpha)
|
||||||
@ -96,7 +97,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite three low-alpha transparent PNGs into one', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer0)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
.overlayWith(fixtures.inputPngOverlayLayer1LowAlpha)
|
||||||
@ -114,7 +115,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite rgb+alpha PNG onto JPEG', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(2048, 1536)
|
.resize(2048, 1536)
|
||||||
@ -127,7 +128,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Composite greyscale+alpha PNG onto JPEG', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
@ -141,7 +142,7 @@ describe('Overlays', function() {
|
|||||||
|
|
||||||
if (sharp.format.webp.input.file) {
|
if (sharp.format.webp.input.file) {
|
||||||
it('Composite WebP onto JPEG', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(300, 300)
|
.resize(300, 300)
|
||||||
@ -212,7 +213,7 @@ describe('Overlays', function() {
|
|||||||
describe('Overlay with numeric gravity', function () {
|
describe('Overlay with numeric gravity', function () {
|
||||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||||
it(gravity, function (done) {
|
it(gravity, function (done) {
|
||||||
var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -233,7 +234,7 @@ describe('Overlays', function() {
|
|||||||
describe('Overlay with string-based gravity', function () {
|
describe('Overlay with string-based gravity', function () {
|
||||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||||
it(gravity, function (done) {
|
it(gravity, function (done) {
|
||||||
var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -254,7 +255,7 @@ describe('Overlays', function() {
|
|||||||
describe('Overlay with tile enabled and gravity', function () {
|
describe('Overlay with tile enabled and gravity', function () {
|
||||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||||
it(gravity, function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.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) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -288,11 +289,10 @@ describe('Overlays', function() {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
fixtures.assertSimilar(expected, data, done);
|
fixtures.assertSimilar(expected, data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with 100px top & 300px left offsets', function (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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -305,7 +305,6 @@ describe('Overlays', function() {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
fixtures.assertSimilar(expected, data, done);
|
fixtures.assertSimilar(expected, data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with only top offset', function () {
|
it('Overlay with only top offset', function () {
|
||||||
@ -340,7 +339,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with 0 offset', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -353,11 +352,10 @@ describe('Overlays', function() {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
fixtures.assertSimilar(expected, data, done);
|
fixtures.assertSimilar(expected, data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with offset and gravity', function (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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -372,11 +370,10 @@ describe('Overlays', function() {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
fixtures.assertSimilar(expected, data, done);
|
fixtures.assertSimilar(expected, data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with offset and gravity and tile', function (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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -391,11 +388,10 @@ describe('Overlays', function() {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
fixtures.assertSimilar(expected, data, done);
|
fixtures.assertSimilar(expected, data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with offset and tile', function (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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -424,7 +420,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with very large offset', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -462,7 +458,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('With tile enabled and image rotated 90 degrees', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
@ -480,7 +476,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('With tile enabled and image rotated 90 degrees and gravity northwest', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
@ -501,7 +497,7 @@ describe('Overlays', function() {
|
|||||||
describe('Overlay with cutout enabled and gravity', function () {
|
describe('Overlay with cutout enabled and gravity', function () {
|
||||||
Object.keys(sharp.gravity).forEach(function (gravity) {
|
Object.keys(sharp.gravity).forEach(function (gravity) {
|
||||||
it(gravity, function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -521,7 +517,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('With cutout enabled and image rotated 90 degrees', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
@ -539,7 +535,7 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('With cutout enabled and image rotated 90 degrees and gravity northwest', function (done) {
|
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)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(80)
|
.resize(80)
|
||||||
@ -580,5 +576,4 @@ describe('Overlays', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'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
|
Including sharp alongside another C++ module that does not require
|
||||||
-stdlib=libc++ (for its C++11 features) has caused clang/llvm to
|
-stdlib=libc++ (for its C++11 features) has caused clang/llvm to
|
||||||
segfault due to the use of static function variables.
|
segfault due to the use of static function variables.
|
||||||
*/
|
*/
|
||||||
it('Require alongside C++ module that does not use libc++', function () {
|
it('Require alongside C++ module that does not use libc++', function () {
|
||||||
var bufferutil = require('bufferutil');
|
const bufferutil = require('bufferutil');
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Resize dimensions', function () {
|
describe('Resize dimensions', function () {
|
||||||
|
|
||||||
it('Exact crop', function (done) {
|
it('Exact crop', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -63,7 +62,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid width - NaN', function (done) {
|
it('Invalid width - NaN', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize('spoons', 240);
|
sharp(fixtures.inputJpg).resize('spoons', 240);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -74,7 +73,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid height - NaN', function (done) {
|
it('Invalid height - NaN', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize(320, 'spoons');
|
sharp(fixtures.inputJpg).resize(320, 'spoons');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -85,7 +84,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid width - float', function (done) {
|
it('Invalid width - float', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize(1.5, 240);
|
sharp(fixtures.inputJpg).resize(1.5, 240);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -96,7 +95,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid height - float', function (done) {
|
it('Invalid height - float', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize(320, 1.5);
|
sharp(fixtures.inputJpg).resize(320, 1.5);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -107,7 +106,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid width - too large', function (done) {
|
it('Invalid width - too large', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize(0x4000, 240);
|
sharp(fixtures.inputJpg).resize(0x4000, 240);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -118,7 +117,7 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid height - too large', function (done) {
|
it('Invalid height - too large', function (done) {
|
||||||
var isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
sharp(fixtures.inputJpg).resize(320, 0x4000);
|
sharp(fixtures.inputJpg).resize(320, 0x4000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -388,5 +387,4 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Rotation', function () {
|
describe('Rotation', function () {
|
||||||
|
|
||||||
['Landscape', 'Portrait'].forEach(function (orientation) {
|
['Landscape', 'Portrait'].forEach(function (orientation) {
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
[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) {
|
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.width);
|
||||||
assert.strictEqual(240, info.height);
|
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.width);
|
||||||
assert.strictEqual(240, metadata.height);
|
assert.strictEqual(240, metadata.height);
|
||||||
done();
|
done();
|
||||||
@ -62,6 +62,7 @@ describe('Rotation', function() {
|
|||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
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(320, metadata.width);
|
||||||
assert.strictEqual(240, metadata.height);
|
assert.strictEqual(240, metadata.height);
|
||||||
done();
|
done();
|
||||||
@ -80,6 +81,7 @@ describe('Rotation', function() {
|
|||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(427, info.height);
|
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);
|
assert.strictEqual(8, metadata.orientation);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -110,6 +112,7 @@ describe('Rotation', function() {
|
|||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
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);
|
assert.strictEqual(3, metadata.orientation);
|
||||||
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
||||||
});
|
});
|
||||||
@ -127,6 +130,7 @@ describe('Rotation', function() {
|
|||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
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);
|
assert.strictEqual(1, metadata.orientation);
|
||||||
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
||||||
});
|
});
|
||||||
@ -227,5 +231,4 @@ describe('Rotation', function() {
|
|||||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Sharpen', function () {
|
describe('Sharpen', function () {
|
||||||
|
|
||||||
it('specific radius 10 (sigma 6)', function (done) {
|
it('specific radius 10 (sigma 6)', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -117,5 +116,4 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Threshold', function () {
|
describe('Threshold', function () {
|
||||||
it('threshold 1 jpeg', function (done) {
|
it('threshold 1 jpeg', function (done) {
|
||||||
@ -11,6 +11,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(1)
|
.threshold(1)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -23,6 +24,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(40)
|
.threshold(40)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -35,6 +37,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128)
|
.threshold(128)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -47,6 +50,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(true)
|
.threshold(true)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -58,6 +62,7 @@ describe('Threshold', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.threshold(false)
|
.threshold(false)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -67,6 +72,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128, { grayscale: true })
|
.threshold(128, { grayscale: true })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -79,6 +85,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -91,6 +98,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -103,6 +111,7 @@ describe('Threshold', function() {
|
|||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
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) {
|
it('threshold default webp transparency', function (done) {
|
||||||
sharp(fixtures.inputWebPWithTransparency)
|
sharp(fixtures.inputWebPWithTransparency)
|
||||||
.threshold()
|
.threshold()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
it('color threshold', function (done) {
|
it('color threshold', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128, {'grayscale': false})
|
.threshold(128, {'grayscale': false})
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var sharp = require('../../index');
|
const sharp = require('../../index');
|
||||||
var fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Trim borders', function () {
|
describe('Trim borders', function () {
|
||||||
|
|
||||||
it('Threshold default', function (done) {
|
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)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(450, 322)
|
.resize(450, 322)
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var fixtures = require('../fixtures');
|
const sharp = require('../../index');
|
||||||
var sharp = require('../../index');
|
|
||||||
|
|
||||||
var defaultConcurrency = sharp.concurrency();
|
const defaultConcurrency = sharp.concurrency();
|
||||||
|
|
||||||
describe('Utilities', function () {
|
describe('Utilities', function () {
|
||||||
|
|
||||||
describe('Cache', function () {
|
describe('Cache', function () {
|
||||||
it('Can be disabled', function () {
|
it('Can be disabled', function () {
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
var cache = sharp.cache(false);
|
const cache = sharp.cache(false);
|
||||||
assert.strictEqual(cache.memory.current, 0);
|
assert.strictEqual(cache.memory.current, 0);
|
||||||
assert.strictEqual(cache.memory.max, 0);
|
assert.strictEqual(cache.memory.max, 0);
|
||||||
assert.strictEqual(typeof cache.memory.high, 'number');
|
assert.strictEqual(typeof cache.memory.high, 'number');
|
||||||
@ -21,13 +19,13 @@ describe('Utilities', function() {
|
|||||||
assert.strictEqual(cache.items.max, 0);
|
assert.strictEqual(cache.items.max, 0);
|
||||||
});
|
});
|
||||||
it('Can be enabled with defaults', function () {
|
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.memory.max, 50);
|
||||||
assert.strictEqual(cache.files.max, 20);
|
assert.strictEqual(cache.files.max, 20);
|
||||||
assert.strictEqual(cache.items.max, 100);
|
assert.strictEqual(cache.items.max, 100);
|
||||||
});
|
});
|
||||||
it('Can be set to zero', function () {
|
it('Can be set to zero', function () {
|
||||||
var cache = sharp.cache({
|
const cache = sharp.cache({
|
||||||
memory: 0,
|
memory: 0,
|
||||||
files: 0,
|
files: 0,
|
||||||
items: 0
|
items: 0
|
||||||
@ -37,7 +35,7 @@ describe('Utilities', function() {
|
|||||||
assert.strictEqual(cache.items.max, 0);
|
assert.strictEqual(cache.items.max, 0);
|
||||||
});
|
});
|
||||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function () {
|
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,
|
memory: 10,
|
||||||
files: 100,
|
files: 100,
|
||||||
items: 1000
|
items: 1000
|
||||||
@ -48,7 +46,7 @@ describe('Utilities', function() {
|
|||||||
});
|
});
|
||||||
it('Ignores invalid values', function () {
|
it('Ignores invalid values', function () {
|
||||||
sharp.cache(true);
|
sharp.cache(true);
|
||||||
var cache = sharp.cache('spoons');
|
const cache = sharp.cache('spoons');
|
||||||
assert.strictEqual(cache.memory.max, 50);
|
assert.strictEqual(cache.memory.max, 50);
|
||||||
assert.strictEqual(cache.files.max, 20);
|
assert.strictEqual(cache.files.max, 20);
|
||||||
assert.strictEqual(cache.items.max, 100);
|
assert.strictEqual(cache.items.max, 100);
|
||||||
@ -73,7 +71,7 @@ describe('Utilities', function() {
|
|||||||
|
|
||||||
describe('Counters', function () {
|
describe('Counters', function () {
|
||||||
it('Have zero value at rest', 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.queue);
|
||||||
assert.strictEqual(0, counters.process);
|
assert.strictEqual(0, counters.process);
|
||||||
});
|
});
|
||||||
@ -81,15 +79,15 @@ describe('Utilities', function() {
|
|||||||
|
|
||||||
describe('SIMD', function () {
|
describe('SIMD', function () {
|
||||||
it('Can get current state', function () {
|
it('Can get current state', function () {
|
||||||
var simd = sharp.simd();
|
const simd = sharp.simd();
|
||||||
assert.strictEqual(typeof simd, 'boolean');
|
assert.strictEqual(typeof simd, 'boolean');
|
||||||
});
|
});
|
||||||
it('Can disable', function () {
|
it('Can disable', function () {
|
||||||
var simd = sharp.simd(false);
|
const simd = sharp.simd(false);
|
||||||
assert.strictEqual(simd, false);
|
assert.strictEqual(simd, false);
|
||||||
});
|
});
|
||||||
it('Can attempt to enable', function () {
|
it('Can attempt to enable', function () {
|
||||||
var simd = sharp.simd(true);
|
const simd = sharp.simd(true);
|
||||||
assert.strictEqual(typeof simd, 'boolean');
|
assert.strictEqual(typeof simd, 'boolean');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -128,5 +126,4 @@ describe('Utilities', function() {
|
|||||||
assert.strictEqual('string', typeof sharp.versions.vips);
|
assert.strictEqual('string', typeof sharp.versions.vips);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user