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,43 +2,43 @@
|
|||||||
|
|
||||||
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 */
|
||||||
sharp(fixtures.inputJpg).resize(width, height).toBuffer(function(err, buffer) {
|
sharp(fixtures.inputJpg).resize(width, height).toBuffer(function (err, buffer) {
|
||||||
buffer = null;
|
buffer = null;
|
||||||
callback(err, new Date().getTime() - start);
|
callback(err, new Date().getTime() - start);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
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');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, function() {
|
}, function () {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
console.dir(sharp.counters());
|
console.dir(sharp.counters());
|
||||||
});
|
});
|
||||||
|
@ -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);
|
||||||
@ -36,18 +35,18 @@ sharp.cache(false);
|
|||||||
sharp.simd(true);
|
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) {
|
||||||
@ -62,12 +61,12 @@ 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) {
|
||||||
@ -85,7 +84,7 @@ async.series({
|
|||||||
if (typeof lwip !== 'undefined') {
|
if (typeof lwip !== 'undefined') {
|
||||||
jpegSuite.add('lwip-file-file', {
|
jpegSuite.add('lwip-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
lwip.open(fixtures.inputJpg, function (err, image) {
|
lwip.open(fixtures.inputJpg, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -105,7 +104,7 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('lwip-buffer-buffer', {
|
}).add('lwip-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
lwip.open(inputJpgBuffer, 'jpg', function (err, image) {
|
lwip.open(inputJpgBuffer, 'jpg', function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -129,7 +128,7 @@ async.series({
|
|||||||
// imagemagick
|
// imagemagick
|
||||||
jpegSuite.add('imagemagick-file-file', {
|
jpegSuite.add('imagemagick-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: fixtures.outputJpg,
|
||||||
@ -138,7 +137,7 @@ async.series({
|
|||||||
height: height,
|
height: height,
|
||||||
format: 'jpg',
|
format: 'jpg',
|
||||||
filter: 'Lanczos'
|
filter: 'Lanczos'
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -151,7 +150,7 @@ async.series({
|
|||||||
if (typeof imagemagickNative !== 'undefined') {
|
if (typeof imagemagickNative !== 'undefined') {
|
||||||
jpegSuite.add('imagemagick-native-buffer-buffer', {
|
jpegSuite.add('imagemagick-native-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
imagemagickNative.convert({
|
imagemagickNative.convert({
|
||||||
srcData: inputJpgBuffer,
|
srcData: inputJpgBuffer,
|
||||||
quality: 80,
|
quality: 80,
|
||||||
@ -173,7 +172,7 @@ async.series({
|
|||||||
// gm
|
// gm
|
||||||
jpegSuite.add('gm-buffer-file', {
|
jpegSuite.add('gm-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(inputJpgBuffer)
|
gm(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -188,7 +187,7 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('gm-buffer-buffer', {
|
}).add('gm-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(inputJpgBuffer)
|
gm(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -204,7 +203,7 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('gm-file-file', {
|
}).add('gm-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputJpg)
|
gm(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -219,7 +218,7 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('gm-file-buffer', {
|
}).add('gm-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputJpg)
|
gm(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -237,10 +236,10 @@ async.series({
|
|||||||
// sharp
|
// sharp
|
||||||
jpegSuite.add('sharp-buffer-file', {
|
jpegSuite.add('sharp-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function(err) {
|
.toFile(fixtures.outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -250,10 +249,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-buffer-buffer', {
|
}).add('sharp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -264,10 +263,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-file', {
|
}).add('sharp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function(err) {
|
.toFile(fixtures.outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -277,22 +276,22 @@ 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);
|
||||||
}
|
}
|
||||||
}).add('sharp-file-buffer', {
|
}).add('sharp-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -303,32 +302,32 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-promise', {
|
}).add('sharp-promise', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then(function(buffer) {
|
.then(function (buffer) {
|
||||||
assert.notStrictEqual(null, buffer);
|
assert.notStrictEqual(null, buffer);
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('cycle', function(event) {
|
}).on('cycle', function (event) {
|
||||||
console.log('jpeg ' + String(event.target));
|
console.log('jpeg ' + String(event.target));
|
||||||
}).on('complete', function() {
|
}).on('complete', function () {
|
||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
},
|
},
|
||||||
// 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) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.sharpen()
|
.sharpen()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -339,11 +338,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-sharpen-radius', {
|
}).add('sharp-sharpen-radius', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.sharpen(3, 1, 3)
|
.sharpen(3, 1, 3)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -354,11 +353,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-blur-mild', {
|
}).add('sharp-blur-mild', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.blur()
|
.blur()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -369,11 +368,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-blur-radius', {
|
}).add('sharp-blur-radius', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.blur(3)
|
.blur(3)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -384,11 +383,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-gamma', {
|
}).add('sharp-gamma', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.gamma()
|
.gamma()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -399,11 +398,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-normalise', {
|
}).add('sharp-normalise', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.normalise()
|
.normalise()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -414,11 +413,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-greyscale', {
|
}).add('sharp-greyscale', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -429,12 +428,12 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-greyscale-gamma', {
|
}).add('sharp-greyscale-gamma', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.gamma()
|
.gamma()
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -445,11 +444,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-progressive', {
|
}).add('sharp-progressive', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.progressive()
|
.progressive()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -460,11 +459,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-without-chroma-subsampling', {
|
}).add('sharp-without-chroma-subsampling', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.withoutChromaSubsampling()
|
.withoutChromaSubsampling()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -475,11 +474,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-rotate', {
|
}).add('sharp-rotate', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -490,11 +489,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-without-simd', {
|
}).add('sharp-without-simd', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp.simd(false);
|
sharp.simd(false);
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
sharp.simd(true);
|
sharp.simd(true);
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -506,11 +505,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-sequentialRead', {
|
}).add('sharp-sequentialRead', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.sequentialRead()
|
.sequentialRead()
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -521,11 +520,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-crop-entropy', {
|
}).add('sharp-crop-entropy', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.crop(sharp.strategy.entropy)
|
.crop(sharp.strategy.entropy)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -536,11 +535,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-crop-attention', {
|
}).add('sharp-crop-attention', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.crop(sharp.strategy.attention)
|
.crop(sharp.strategy.attention)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -549,21 +548,21 @@ async.series({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('cycle', function(event) {
|
}).on('cycle', function (event) {
|
||||||
console.log('operations ' + String(event.target));
|
console.log('operations ' + String(event.target));
|
||||||
}).on('complete', function() {
|
}).on('complete', function () {
|
||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
},
|
},
|
||||||
// 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) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height, { kernel: 'cubic' })
|
.resize(width, height, { kernel: 'cubic' })
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -574,10 +573,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-lanczos2', {
|
}).add('sharp-lanczos2', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height, { kernel: 'lanczos2' })
|
.resize(width, height, { kernel: 'lanczos2' })
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -588,10 +587,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-lanczos3', {
|
}).add('sharp-lanczos3', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height, { kernel: 'lanczos3' })
|
.resize(width, height, { kernel: 'lanczos3' })
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -600,25 +599,25 @@ async.series({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('cycle', function(event) {
|
}).on('cycle', function (event) {
|
||||||
console.log('kernels ' + String(event.target));
|
console.log('kernels ' + String(event.target));
|
||||||
}).on('complete', function() {
|
}).on('complete', function () {
|
||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
},
|
},
|
||||||
// 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) {
|
||||||
@ -632,12 +631,12 @@ 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) {
|
||||||
@ -654,7 +653,7 @@ async.series({
|
|||||||
if (typeof lwip !== 'undefined') {
|
if (typeof lwip !== 'undefined') {
|
||||||
pngSuite.add('lwip-buffer-buffer', {
|
pngSuite.add('lwip-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
lwip.open(inputPngBuffer, 'png', function (err, image) {
|
lwip.open(inputPngBuffer, 'png', function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -678,14 +677,14 @@ async.series({
|
|||||||
// imagemagick
|
// imagemagick
|
||||||
pngSuite.add('imagemagick-file-file', {
|
pngSuite.add('imagemagick-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputPng,
|
srcPath: fixtures.inputPng,
|
||||||
dstPath: fixtures.outputPng,
|
dstPath: fixtures.outputPng,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
filter: 'Lanczos'
|
filter: 'Lanczos'
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -698,7 +697,7 @@ async.series({
|
|||||||
if (typeof imagemagickNative !== 'undefined') {
|
if (typeof imagemagickNative !== 'undefined') {
|
||||||
pngSuite.add('imagemagick-native-buffer-buffer', {
|
pngSuite.add('imagemagick-native-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
imagemagickNative.convert({
|
imagemagickNative.convert({
|
||||||
srcData: inputPngBuffer,
|
srcData: inputPngBuffer,
|
||||||
width: width,
|
width: width,
|
||||||
@ -713,7 +712,7 @@ async.series({
|
|||||||
// gm
|
// gm
|
||||||
pngSuite.add('gm-file-file', {
|
pngSuite.add('gm-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputPng)
|
gm(fixtures.inputPng)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -727,7 +726,7 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('gm-file-buffer', {
|
}).add('gm-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputPng)
|
gm(fixtures.inputPng)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -744,10 +743,10 @@ async.series({
|
|||||||
// sharp
|
// sharp
|
||||||
pngSuite.add('sharp-buffer-file', {
|
pngSuite.add('sharp-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputPng, function(err) {
|
.toFile(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -757,10 +756,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-buffer-buffer', {
|
}).add('sharp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -771,10 +770,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-file', {
|
}).add('sharp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputPng, function(err) {
|
.toFile(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -784,10 +783,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-buffer', {
|
}).add('sharp-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -798,11 +797,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-progressive', {
|
}).add('sharp-progressive', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.progressive()
|
.progressive()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -813,11 +812,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-withoutAdaptiveFiltering', {
|
}).add('sharp-withoutAdaptiveFiltering', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.withoutAdaptiveFiltering()
|
.withoutAdaptiveFiltering()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -827,21 +826,21 @@ async.series({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
pngSuite.on('cycle', function(event) {
|
pngSuite.on('cycle', function (event) {
|
||||||
console.log(' png ' + String(event.target));
|
console.log(' png ' + String(event.target));
|
||||||
}).on('complete', function() {
|
}).on('complete', function () {
|
||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
},
|
},
|
||||||
// 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) {
|
||||||
sharp(inputWebPBuffer)
|
sharp(inputWebPBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function(err) {
|
.toFile(fixtures.outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -851,10 +850,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-buffer-buffer', {
|
}).add('sharp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputWebPBuffer)
|
sharp(inputWebPBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -865,10 +864,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-file', {
|
}).add('sharp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function(err) {
|
.toFile(fixtures.outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -878,10 +877,10 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-buffer', {
|
}).add('sharp-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputWebp)
|
sharp(fixtures.inputWebp)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -890,15 +889,15 @@ async.series({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('cycle', function(event) {
|
}).on('cycle', function (event) {
|
||||||
console.log('webp ' + String(event.target));
|
console.log('webp ' + String(event.target));
|
||||||
}).on('complete', function() {
|
}).on('complete', function () {
|
||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function (err, results) {
|
||||||
assert(!err, err);
|
assert(!err, err);
|
||||||
Object.keys(results).forEach(function(format) {
|
Object.keys(results).forEach(function (format) {
|
||||||
if (results[format].toString().substr(0, 5) !== 'sharp') {
|
if (results[format].toString().substr(0, 5) !== 'sharp') {
|
||||||
console.log('sharp was slower than ' + results[format] + ' for ' + format);
|
console.log('sharp was slower than ' + results[format] + ' for ' + format);
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
'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);
|
||||||
};
|
};
|
||||||
|
|
||||||
new Benchmark.Suite('random').add('imagemagick', {
|
new Benchmark.Suite('random').add('imagemagick', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: fixtures.outputJpg,
|
||||||
@ -29,7 +29,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
height: randomDimension(),
|
height: randomDimension(),
|
||||||
format: 'jpg',
|
format: 'jpg',
|
||||||
filter: 'Lanczos'
|
filter: 'Lanczos'
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -39,7 +39,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
}
|
}
|
||||||
}).add('gm', {
|
}).add('gm', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputJpg)
|
gm(fixtures.inputJpg)
|
||||||
.resize(randomDimension(), randomDimension())
|
.resize(randomDimension(), randomDimension())
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
@ -55,10 +55,10 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
}
|
}
|
||||||
}).add('sharp', {
|
}).add('sharp', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function(deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(randomDimension(), randomDimension())
|
.resize(randomDimension(), randomDimension())
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -67,9 +67,9 @@ 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');
|
||||||
@ -10,7 +9,7 @@ const client = tumblr.createClient({
|
|||||||
consumer_secret: '***'
|
consumer_secret: '***'
|
||||||
});
|
});
|
||||||
|
|
||||||
const fetchImages = function(offset) {
|
const fetchImages = function (offset) {
|
||||||
console.log(`Fetching offset ${offset}`);
|
console.log(`Fetching offset ${offset}`);
|
||||||
client.posts('humanae', {
|
client.posts('humanae', {
|
||||||
type: 'photo',
|
type: 'photo',
|
||||||
@ -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]);
|
||||||
@ -22,7 +21,7 @@ a.sort((v1, v2) => v1 - v2);
|
|||||||
b.sort((v1, v2) => v1 - v2);
|
b.sort((v1, v2) => v1 - v2);
|
||||||
|
|
||||||
// Convert from 0..1 to -128..128
|
// Convert from 0..1 to -128..128
|
||||||
const convert = function(v) {
|
const convert = function (v) {
|
||||||
return Math.round(256 * (v - 0.5));
|
return Math.round(256 * (v - 0.5));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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');
|
||||||
@ -16,7 +15,7 @@ const concurrency = os.cpus().length;
|
|||||||
|
|
||||||
const scores = {};
|
const scores = {};
|
||||||
|
|
||||||
const incrementScore = function(accuracy, crop) {
|
const incrementScore = function (accuracy, crop) {
|
||||||
if (typeof scores[accuracy] === 'undefined') {
|
if (typeof scores[accuracy] === 'undefined') {
|
||||||
scores[accuracy] = {};
|
scores[accuracy] = {};
|
||||||
}
|
}
|
||||||
@ -29,36 +28,36 @@ const incrementScore = function(accuracy, crop) {
|
|||||||
const userData = require('./userData.json');
|
const userData = require('./userData.json');
|
||||||
const files = Object.keys(userData);
|
const files = Object.keys(userData);
|
||||||
|
|
||||||
async.eachLimit(files, concurrency, function(file, done) {
|
async.eachLimit(files, concurrency, function (file, done) {
|
||||||
const filename = path.join(__dirname, 'Image', file);
|
const filename = path.join(__dirname, 'Image', file);
|
||||||
const salientWidth = userData[file].right - userData[file].left;
|
const salientWidth = userData[file].right - userData[file].left;
|
||||||
const salientHeight = userData[file].bottom - userData[file].top;
|
const salientHeight = userData[file].bottom - userData[file].top;
|
||||||
sharp(filename).metadata(function(err, metadata) {
|
sharp(filename).metadata(function (err, metadata) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
async.each(Object.keys(crops), function(crop, done) {
|
async.each(Object.keys(crops), function (crop, done) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
// Left edge accuracy
|
// Left edge accuracy
|
||||||
function(done) {
|
function (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
|
||||||
function(done) {
|
function (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);
|
||||||
}, done);
|
}, done);
|
||||||
});
|
});
|
||||||
}, function() {
|
}, function () {
|
||||||
const report = [];
|
const report = [];
|
||||||
Object.keys(scores).forEach(function(accuracy) {
|
Object.keys(scores).forEach(function (accuracy) {
|
||||||
report.push(
|
report.push(
|
||||||
Object.assign({
|
Object.assign({
|
||||||
accuracy: parseInt(accuracy, 10)
|
accuracy: parseInt(accuracy, 10)
|
||||||
|
@ -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');
|
||||||
@ -8,8 +7,8 @@ const userDataDir = 'UserData';
|
|||||||
|
|
||||||
const images = {};
|
const images = {};
|
||||||
|
|
||||||
const median = function(values) {
|
const median = function (values) {
|
||||||
values.sort(function(a,b) {
|
values.sort(function (a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
const half = Math.floor(values.length / 2);
|
const half = Math.floor(values.length / 2);
|
||||||
@ -21,7 +20,7 @@ const median = function(values) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// List of files
|
// List of files
|
||||||
fs.readdirSync(userDataDir).forEach(function(file) {
|
fs.readdirSync(userDataDir).forEach(function (file) {
|
||||||
// Contents of file
|
// Contents of file
|
||||||
const lines = fs.readFileSync(path.join(userDataDir, file), {encoding: 'utf-8'}).split(/\r\n/);
|
const lines = fs.readFileSync(path.join(userDataDir, file), {encoding: 'utf-8'}).split(/\r\n/);
|
||||||
// First line = number of entries
|
// First line = number of entries
|
||||||
@ -39,8 +38,11 @@ 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 = [];
|
||||||
regions.forEach(function(region) {
|
const tops = [];
|
||||||
|
const rights = [];
|
||||||
|
const bottoms = [];
|
||||||
|
regions.forEach(function (region) {
|
||||||
if (region.indexOf(' ') !== -1) {
|
if (region.indexOf(' ') !== -1) {
|
||||||
const coords = region.split(' ');
|
const coords = region.split(' ');
|
||||||
lefts.push(parseInt(coords[0], 10));
|
lefts.push(parseInt(coords[0], 10));
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
'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()
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(400, info.width);
|
assert.strictEqual(400, info.width);
|
||||||
assert.strictEqual(300, info.height);
|
assert.strictEqual(300, info.height);
|
||||||
@ -18,12 +17,12 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to RGB orange', function(done) {
|
it('Flatten to RGB orange', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten()
|
.flatten()
|
||||||
.background({r: 255, g: 102, b: 0})
|
.background({r: 255, g: 102, b: 0})
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(400, info.width);
|
assert.strictEqual(400, info.width);
|
||||||
assert.strictEqual(300, info.height);
|
assert.strictEqual(300, info.height);
|
||||||
@ -31,12 +30,12 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to CSS/hex orange', function(done) {
|
it('Flatten to CSS/hex orange', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten()
|
.flatten()
|
||||||
.background('#ff6600')
|
.background('#ff6600')
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(400, info.width);
|
assert.strictEqual(400, info.width);
|
||||||
assert.strictEqual(300, info.height);
|
assert.strictEqual(300, info.height);
|
||||||
@ -44,12 +43,12 @@ 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})
|
||||||
.toFile(output, function(err, info) {
|
.toFile(output, 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(32, info.width);
|
assert.strictEqual(32, info.width);
|
||||||
@ -59,10 +58,10 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not flatten', function(done) {
|
it('Do not flatten', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten(false)
|
.flatten(false)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
@ -70,11 +69,11 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Ignored for JPEG', function(done) {
|
it('Ignored for JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.background('#ff0000')
|
.background('#ff0000')
|
||||||
.flatten()
|
.flatten()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -82,13 +81,13 @@ describe('Alpha transparency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function(done) {
|
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) {
|
||||||
if (err) {
|
if (err) {
|
||||||
done(err);
|
done(err);
|
||||||
} else {
|
} else {
|
||||||
@ -98,13 +97,13 @@ 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) {
|
||||||
if (err) {
|
if (err) {
|
||||||
done(err);
|
done(err);
|
||||||
} else {
|
} else {
|
||||||
@ -113,5 +112,4 @@ describe('Alpha transparency', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
'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,
|
||||||
sharp.bool.eor
|
sharp.bool.eor
|
||||||
]
|
]
|
||||||
.forEach(function(op) {
|
.forEach(function (op) {
|
||||||
it(op + ' operation', function(done) {
|
it(op + ' operation', function (done) {
|
||||||
sharp(fixtures.inputPngBooleanNoAlpha)
|
sharp(fixtures.inputPngBooleanNoAlpha)
|
||||||
.bandbool(op)
|
.bandbool(op)
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(200, info.width);
|
assert.strictEqual(200, info.width);
|
||||||
assert.strictEqual(200, info.height);
|
assert.strictEqual(200, info.height);
|
||||||
@ -26,23 +25,24 @@ describe('Bandbool per-channel boolean operations', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sRGB image retains 3 channels', function(done) {
|
it('sRGB image retains 3 channels', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid operation', function() {
|
it('Invalid operation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().bandbool('fail');
|
sharp().bandbool('fail');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Missing operation', function() {
|
it('Missing operation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().bandbool();
|
sharp().bandbool();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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);
|
||||||
@ -19,11 +19,12 @@ describe('Blur', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 10', function(done) {
|
it('specific radius 10', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -31,11 +32,12 @@ describe('Blur', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 0.3', function(done) {
|
it('specific radius 0.3', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -43,11 +45,12 @@ describe('Blur', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('mild blur', function(done) {
|
it('mild blur', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -55,17 +58,18 @@ describe('Blur', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid radius', function() {
|
it('invalid radius', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).blur(0.1);
|
sharp(fixtures.inputJpg).blur(0.1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('blurred image is smaller than non-blurred', function(done) {
|
it('blurred image is smaller than non-blurred', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -73,7 +77,8 @@ describe('Blur', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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,26 +1,25 @@
|
|||||||
'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');
|
|
||||||
|
|
||||||
describe('Boolean operation between two images', function() {
|
const fixtures = require('../fixtures');
|
||||||
|
const sharp = require('../../index');
|
||||||
|
|
||||||
var inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
describe('Boolean operation between two images', function () {
|
||||||
|
const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||||
|
|
||||||
[
|
[
|
||||||
sharp.bool.and,
|
sharp.bool.and,
|
||||||
sharp.bool.or,
|
sharp.bool.or,
|
||||||
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)
|
||||||
.boolean(fixtures.inputJpgBooleanTest, op)
|
.boolean(fixtures.inputJpgBooleanTest, op)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -28,11 +27,11 @@ describe('Boolean operation between two images', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(op + ' operation, buffer', function(done) {
|
it(op + ' operation, buffer', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.boolean(inputJpgBooleanTestBuffer, op)
|
.boolean(inputJpgBooleanTestBuffer, op)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -40,15 +39,15 @@ describe('Boolean operation between two images', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(op + ' operation, raw', function(done) {
|
it(op + ' operation, raw', function (done) {
|
||||||
sharp(fixtures.inputJpgBooleanTest)
|
sharp(fixtures.inputJpgBooleanTest)
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.boolean(data, op, { raw: info })
|
.boolean(data, op, { raw: info })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -56,23 +55,22 @@ describe('Boolean operation between two images', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid operation', function() {
|
it('Invalid operation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().boolean(fixtures.inputJpgBooleanTest, 'fail');
|
sharp().boolean(fixtures.inputJpgBooleanTest, 'fail');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid operation, non-string', function() {
|
it('Invalid operation, non-string', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().boolean(fixtures.inputJpgBooleanTest, null);
|
sharp().boolean(fixtures.inputJpgBooleanTest, null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Missing input', function() {
|
it('Missing input', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().boolean();
|
sharp().boolean();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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,27 +1,26 @@
|
|||||||
'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);
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function () {
|
||||||
sharp.cache(true);
|
sharp.cache(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
@ -36,10 +35,10 @@ 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;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
@ -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,20 +1,19 @@
|
|||||||
'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)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('To greyscale with gamma correction', function(done) {
|
it('To greyscale with gamma correction', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.gamma()
|
.gamma()
|
||||||
@ -22,19 +21,19 @@ describe('Colour space conversion', function() {
|
|||||||
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Not to greyscale', function(done) {
|
it('Not to greyscale', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.greyscale(false)
|
.greyscale(false)
|
||||||
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Greyscale with single channel output', function(done) {
|
it('Greyscale with single channel output', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(1, info.channels);
|
assert.strictEqual(1, info.channels);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -44,10 +43,10 @@ describe('Colour space conversion', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) {
|
if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) {
|
||||||
it('From 1-bit TIFF to sRGB WebP [slow]', function(done) {
|
it('From 1-bit TIFF to sRGB WebP [slow]', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.webp()
|
.webp()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
@ -56,10 +55,10 @@ describe('Colour space conversion', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('From CMYK to sRGB', function(done) {
|
it('From CMYK to sRGB', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -68,12 +67,12 @@ describe('Colour space conversion', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From CMYK to sRGB with white background, not yellow', function(done) {
|
it('From CMYK to sRGB with white background, not yellow', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.background('white')
|
.background('white')
|
||||||
.embed()
|
.embed()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -82,10 +81,10 @@ describe('Colour space conversion', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From profile-less CMYK to sRGB', function(done) {
|
it('From profile-less CMYK to sRGB', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCmykNoProfile)
|
sharp(fixtures.inputJpgWithCmykNoProfile)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -93,8 +92,8 @@ describe('Colour space conversion', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid input', function() {
|
it('Invalid input', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.toColourspace(null);
|
.toColourspace(null);
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
'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({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -15,10 +14,10 @@ describe('Convolve', function() {
|
|||||||
scale: 50,
|
scale: 50,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
kernel: [ 10, 20, 10,
|
kernel: [ 10, 20, 10,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
10, 20, 10 ]
|
10, 20, 10 ]
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -27,7 +26,7 @@ describe('Convolve', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific convolution kernel 2', function(done) {
|
it('specific convolution kernel 2', function (done) {
|
||||||
sharp(fixtures.inputPngStripesH)
|
sharp(fixtures.inputPngStripesH)
|
||||||
.convolve({
|
.convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -36,7 +35,7 @@ describe('Convolve', function() {
|
|||||||
2, 0, 2,
|
2, 0, 2,
|
||||||
1, 0, 1 ]
|
1, 0, 1 ]
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -45,7 +44,7 @@ describe('Convolve', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('horizontal Sobel operator', function(done) {
|
it('horizontal Sobel operator', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.convolve({
|
.convolve({
|
||||||
@ -55,7 +54,7 @@ describe('Convolve', function() {
|
|||||||
-2, 0, 2,
|
-2, 0, 2,
|
||||||
-1, 0, 1 ]
|
-1, 0, 1 ]
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -64,14 +63,14 @@ describe('Convolve', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('invalid kernel specification', function() {
|
describe('invalid kernel specification', function () {
|
||||||
it('missing', function() {
|
it('missing', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).convolve({});
|
sharp(fixtures.inputJpg).convolve({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('incorrect data format', function() {
|
it('incorrect data format', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).convolve({
|
sharp(fixtures.inputJpg).convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
height: 3,
|
height: 3,
|
||||||
@ -79,8 +78,8 @@ describe('Convolve', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('incorrect dimensions', function() {
|
it('incorrect dimensions', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).convolve({
|
sharp(fixtures.inputJpg).convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
height: 4,
|
height: 4,
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
'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({
|
||||||
files: [file],
|
files: [file],
|
||||||
@ -34,18 +33,16 @@ describe('cpplint', function() {
|
|||||||
indentation_namespace: false
|
indentation_namespace: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, function(err, report) {
|
}, function (err, report) {
|
||||||
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',
|
||||||
@ -113,12 +112,12 @@ describe('Crop', function() {
|
|||||||
gravity: sharp.gravity.northwest,
|
gravity: sharp.gravity.northwest,
|
||||||
fixture: 'gravity-west.jpg'
|
fixture: 'gravity-west.jpg'
|
||||||
}
|
}
|
||||||
].forEach(function(settings) {
|
].forEach(function (settings) {
|
||||||
it(settings.name + ' gravity', function(done) {
|
it(settings.name + ' gravity', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(settings.width, settings.height)
|
.resize(settings.width, settings.height)
|
||||||
.crop(settings.gravity)
|
.crop(settings.gravity)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(settings.width, info.width);
|
assert.strictEqual(settings.width, info.width);
|
||||||
assert.strictEqual(settings.height, info.height);
|
assert.strictEqual(settings.height, info.height);
|
||||||
@ -127,11 +126,11 @@ describe('Crop', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Allows specifying the gravity as a string', function(done) {
|
it('Allows specifying the gravity as a string', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320)
|
.resize(80, 320)
|
||||||
.crop('east')
|
.crop('east')
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(320, info.height);
|
assert.strictEqual(320, info.height);
|
||||||
@ -139,34 +138,33 @@ describe('Crop', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid values fail', function() {
|
it('Invalid values fail', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().crop(9);
|
sharp().crop(9);
|
||||||
});
|
});
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().crop(1.1);
|
sharp().crop(1.1);
|
||||||
});
|
});
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().crop(-1);
|
sharp().crop(-1);
|
||||||
});
|
});
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().crop('zoinks');
|
sharp().crop('zoinks');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Uses default value when none specified', function() {
|
it('Uses default value when none specified', function () {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function () {
|
||||||
sharp().crop();
|
sharp().crop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
.crop(sharp.strategy.entropy)
|
.crop(sharp.strategy.entropy)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -178,11 +176,11 @@ describe('Crop', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function(done) {
|
it('PNG', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.crop(sharp.strategy.entropy)
|
.crop(sharp.strategy.entropy)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
@ -193,16 +191,14 @@ 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)
|
||||||
.crop(sharp.strategy.attention)
|
.crop(sharp.strategy.attention)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -214,11 +210,11 @@ describe('Crop', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function(done) {
|
it('PNG', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.crop(sharp.strategy.attention)
|
.crop(sharp.strategy.attention)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
@ -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,18 +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('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()
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -24,13 +23,13 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.output.buffer) {
|
if (sharp.format.webp.output.buffer) {
|
||||||
it('JPEG within WebP, to include alpha channel', function(done) {
|
it('JPEG within WebP, to include alpha channel', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.background({r: 0, g: 0, b: 0, a: 0})
|
.background({r: 0, g: 0, b: 0, a: 0})
|
||||||
.embed()
|
.embed()
|
||||||
.webp()
|
.webp()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
@ -42,11 +41,11 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('PNG with alpha channel', function(done) {
|
it('PNG with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(50, 50)
|
.resize(50, 50)
|
||||||
.embed()
|
.embed()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -57,11 +56,11 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel', function(done) {
|
it('16-bit PNG with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 16)
|
.resize(32, 16)
|
||||||
.embed()
|
.embed()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -72,12 +71,12 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel onto RGBA', function(done) {
|
it('16-bit PNG with alpha channel onto RGBA', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 16)
|
.resize(32, 16)
|
||||||
.embed()
|
.embed()
|
||||||
.background({r: 0, g: 0, b: 0, a: 0})
|
.background({r: 0, g: 0, b: 0, a: 0})
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -88,12 +87,12 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG with 2 channels', function(done) {
|
it('PNG with 2 channels', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(32, 16)
|
.resize(32, 16)
|
||||||
.embed()
|
.embed()
|
||||||
.background({r: 0, g: 0, b: 0, a: 0})
|
.background({r: 0, g: 0, b: 0, a: 0})
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -104,11 +103,11 @@ describe('Embed', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Enlarge and embed', function(done) {
|
it('Enlarge and embed', function (done) {
|
||||||
sharp(fixtures.inputPngWithOneColor)
|
sharp(fixtures.inputPngWithOneColor)
|
||||||
.embed()
|
.embed()
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -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,18 +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('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)
|
||||||
.background({r: 255, g: 0, b: 0})
|
.background({r: 255, g: 0, b: 0})
|
||||||
.extend(10)
|
.extend(10)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(140, info.width);
|
assert.strictEqual(140, info.width);
|
||||||
assert.strictEqual(118, info.height);
|
assert.strictEqual(118, info.height);
|
||||||
@ -20,12 +19,12 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('extend sides unequally with RGBA', function(done) {
|
it('extend sides unequally with RGBA', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.background({r: 0, g: 0, b: 0, a: 0})
|
.background({r: 0, g: 0, b: 0, a: 0})
|
||||||
.extend({top: 50, bottom: 0, left: 10, right: 35})
|
.extend({top: 50, bottom: 0, left: 10, right: 35})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(165, info.width);
|
assert.strictEqual(165, info.width);
|
||||||
assert.strictEqual(170, info.height);
|
assert.strictEqual(170, info.height);
|
||||||
@ -33,32 +32,32 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('missing parameter fails', function() {
|
it('missing parameter fails', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().extend();
|
sharp().extend();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('negative fails', function() {
|
it('negative fails', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().extend(-1);
|
sharp().extend(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('partial object fails', function() {
|
it('partial object fails', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().extend({top: 1});
|
sharp().extend({top: 1});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add alpha channel before extending with a transparent Background', function( done ){
|
it('should add alpha channel before extending with a transparent Background', function (done) {
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.background({r: 0, g: 0, b: 0, a: 0})
|
.background({r: 0, g: 0, b: 0, a: 0})
|
||||||
.toFormat( sharp.format.png )
|
.toFormat(sharp.format.png)
|
||||||
.extend({top: 0, bottom: 10, left: 0, right: 10})
|
.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,16 +1,15 @@
|
|||||||
'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 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(20, info.width);
|
assert.strictEqual(20, info.width);
|
||||||
assert.strictEqual(20, info.height);
|
assert.strictEqual(20, info.height);
|
||||||
@ -18,10 +17,10 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function(done) {
|
it('PNG', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(400, info.width);
|
assert.strictEqual(400, info.width);
|
||||||
assert.strictEqual(200, info.height);
|
assert.strictEqual(200, info.height);
|
||||||
@ -30,10 +29,10 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.output.file) {
|
if (sharp.format.webp.output.file) {
|
||||||
it('WebP', function(done) {
|
it('WebP', function (done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(125, info.width);
|
assert.strictEqual(125, info.width);
|
||||||
assert.strictEqual(200, info.height);
|
assert.strictEqual(200, info.height);
|
||||||
@ -43,11 +42,11 @@ describe('Partial image extraction', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.tiff.output.file) {
|
if (sharp.format.tiff.output.file) {
|
||||||
it('TIFF', function(done) {
|
it('TIFF', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(341, info.width);
|
assert.strictEqual(341, info.width);
|
||||||
assert.strictEqual(529, info.height);
|
assert.strictEqual(529, info.height);
|
||||||
@ -56,11 +55,11 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Before resize', function(done) {
|
it('Before resize', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
||||||
.resize(100, 100)
|
.resize(100, 100)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
@ -68,12 +67,12 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('After resize and crop', function(done) {
|
it('After resize and crop', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(500, 500)
|
.resize(500, 500)
|
||||||
.crop(sharp.gravity.north)
|
.crop(sharp.gravity.north)
|
||||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
@ -81,13 +80,13 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Before and after resize and crop', function(done) {
|
it('Before and after resize and crop', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
||||||
.resize(500, 500)
|
.resize(500, 500)
|
||||||
.crop(sharp.gravity.north)
|
.crop(sharp.gravity.north)
|
||||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
assert.strictEqual(100, info.height);
|
assert.strictEqual(100, info.height);
|
||||||
@ -95,11 +94,11 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Extract then rotate', function(done) {
|
it('Extract then rotate', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(280, info.width);
|
assert.strictEqual(280, info.width);
|
||||||
assert.strictEqual(380, info.height);
|
assert.strictEqual(380, info.height);
|
||||||
@ -107,11 +106,11 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate then extract', function(done) {
|
it('Rotate then extract', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(280, info.width);
|
assert.strictEqual(280, info.width);
|
||||||
assert.strictEqual(380, info.height);
|
assert.strictEqual(380, info.height);
|
||||||
@ -119,69 +118,69 @@ describe('Partial image extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid parameters', function() {
|
describe('Invalid parameters', function () {
|
||||||
describe('using the legacy extract(top,left,width,height) syntax', function () {
|
describe('using the legacy extract(top,left,width,height) syntax', function () {
|
||||||
it('String top', function() {
|
it('String top', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-integral left', function() {
|
it('Non-integral left', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Negative width - negative', function() {
|
it('Negative width - negative', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Null height', function() {
|
it('Null height', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Undefined', function() {
|
it('Undefined', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract();
|
sharp(fixtures.inputJpg).extract();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('String top', function() {
|
it('String top', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 'spoons', width: 10, height: 10 });
|
sharp(fixtures.inputJpg).extract({ left: 10, top: 'spoons', width: 10, height: 10 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-integral left', function() {
|
it('Non-integral left', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract({ left: 10.2, top: 10, width: 10, height: 10 });
|
sharp(fixtures.inputJpg).extract({ left: 10.2, top: 10, width: 10, height: 10 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Negative width - negative', function() {
|
it('Negative width - negative', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: -10, height: 10 });
|
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: -10, height: 10 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Null height', function() {
|
it('Null height', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: 10, height: null });
|
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: 10, height: null });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Bad image area', function(done) {
|
it('Bad image area', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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,17 +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('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')
|
||||||
.resize(320,240)
|
.resize(320, 240)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -19,11 +18,11 @@ describe('Image channel extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Green channel', function(done) {
|
it('Green channel', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('green')
|
.extractChannel('green')
|
||||||
.resize(320,240)
|
.resize(320, 240)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -31,11 +30,11 @@ describe('Image channel extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Blue channel', function(done) {
|
it('Blue channel', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('blue')
|
.extractChannel('blue')
|
||||||
.resize(320,240)
|
.resize(320, 240)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -43,11 +42,11 @@ describe('Image channel extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Blue channel by number', function(done) {
|
it('Blue channel by number', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel(2)
|
.extractChannel(2)
|
||||||
.resize(320,240)
|
.resize(320, 240)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@ -55,27 +54,26 @@ describe('Image channel extraction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid channel number', function() {
|
it('Invalid channel number', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel(-1);
|
.extractChannel(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No arguments', function() {
|
it('No arguments', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel();
|
.extractChannel();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-existant channel', function(done) {
|
it('Non-existant channel', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.extractChannel(1)
|
.extractChannel(1)
|
||||||
.toBuffer(function(err) {
|
.toBuffer(function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
'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 () {
|
||||||
it('should throw an Error when images have a different number of channels', function() {
|
it('should throw an Error when images have a different number of channels', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer1, fixtures.inputJpg);
|
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer1, fixtures.inputJpg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should throw an Error when images have different dimensions', function() {
|
it('should throw an Error when images have different dimensions', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
fixtures.assertMaxColourDistance(fixtures.inputJpg, fixtures.inputJpgWithExif);
|
fixtures.assertMaxColourDistance(fixtures.inputJpg, fixtures.inputJpgWithExif);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
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 () {
|
||||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer0, fixtures.inputPngOverlayLayer1, 100);
|
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer0, fixtures.inputPngOverlayLayer1, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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);
|
||||||
@ -18,11 +18,12 @@ describe('Gamma correction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('value of 2.2 (default)', function(done) {
|
it('value of 2.2 (default)', function (done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.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);
|
||||||
@ -30,11 +31,12 @@ describe('Gamma correction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('value of 3.0', function(done) {
|
it('value of 3.0', function (done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.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);
|
||||||
@ -42,21 +44,21 @@ describe('Gamma correction', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('alpha transparency', function(done) {
|
it('alpha transparency', function (done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid value', function() {
|
it('invalid value', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
'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,
|
||||||
sharp.kernel.lanczos2,
|
sharp.kernel.lanczos2,
|
||||||
sharp.kernel.lanczos3
|
sharp.kernel.lanczos3
|
||||||
].forEach(function(kernel) {
|
].forEach(function (kernel) {
|
||||||
it(kernel, function(done) {
|
it(kernel, function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, null, { kernel: kernel })
|
.resize(320, null, { kernel: kernel })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -26,7 +25,7 @@ describe('Interpolators and kernels', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Enlargers', function() {
|
describe('Enlargers', function () {
|
||||||
[
|
[
|
||||||
sharp.interpolator.nearest,
|
sharp.interpolator.nearest,
|
||||||
sharp.interpolator.bilinear,
|
sharp.interpolator.bilinear,
|
||||||
@ -34,11 +33,11 @@ describe('Interpolators and kernels', function() {
|
|||||||
sharp.interpolator.nohalo,
|
sharp.interpolator.nohalo,
|
||||||
sharp.interpolator.locallyBoundedBicubic,
|
sharp.interpolator.locallyBoundedBicubic,
|
||||||
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
sharp.interpolator.vertexSplitQuadraticBasisSpline
|
||||||
].forEach(function(interpolator) {
|
].forEach(function (interpolator) {
|
||||||
it(interpolator, function(done) {
|
it(interpolator, function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, null, { interpolator: interpolator })
|
.resize(320, null, { interpolator: interpolator })
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -48,16 +47,15 @@ describe('Interpolators and kernels', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unknown kernel throws', function() {
|
it('unknown kernel throws', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().resize(null, null, { kernel: 'unknown' });
|
sharp().resize(null, null, { kernel: 'unknown' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unknown interpolator throws', function() {
|
it('unknown interpolator throws', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().resize(null, null, { interpolator: 'unknown' });
|
sharp().resize(null, null, { interpolator: 'unknown' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
484
test/unit/io.js
484
test/unit/io.js
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,16 @@
|
|||||||
'use strict';
|
'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;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual(2725, metadata.width);
|
assert.strictEqual(2725, metadata.width);
|
||||||
@ -28,8 +27,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG with EXIF/ICC', function(done) {
|
it('JPEG with EXIF/ICC', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif).metadata(function(err, metadata) {
|
sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual(450, metadata.width);
|
assert.strictEqual(450, metadata.width);
|
||||||
@ -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();
|
||||||
@ -58,8 +57,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.tiff.input.file) {
|
if (sharp.format.tiff.input.file) {
|
||||||
it('TIFF', function(done) {
|
it('TIFF', function (done) {
|
||||||
sharp(fixtures.inputTiff).metadata(function(err, metadata) {
|
sharp(fixtures.inputTiff).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', metadata.format);
|
assert.strictEqual('tiff', metadata.format);
|
||||||
assert.strictEqual(2464, metadata.width);
|
assert.strictEqual(2464, metadata.width);
|
||||||
@ -77,8 +76,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('PNG', function(done) {
|
it('PNG', function (done) {
|
||||||
sharp(fixtures.inputPng).metadata(function(err, metadata) {
|
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', metadata.format);
|
assert.strictEqual('png', metadata.format);
|
||||||
assert.strictEqual(2809, metadata.width);
|
assert.strictEqual(2809, metadata.width);
|
||||||
@ -95,8 +94,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Transparent PNG', function(done) {
|
it('Transparent PNG', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency).metadata(function(err, metadata) {
|
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', metadata.format);
|
assert.strictEqual('png', metadata.format);
|
||||||
assert.strictEqual(2048, metadata.width);
|
assert.strictEqual(2048, metadata.width);
|
||||||
@ -114,8 +113,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.input.file) {
|
if (sharp.format.webp.input.file) {
|
||||||
it('WebP', function(done) {
|
it('WebP', function (done) {
|
||||||
sharp(fixtures.inputWebP).metadata(function(err, metadata) {
|
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', metadata.format);
|
assert.strictEqual('webp', metadata.format);
|
||||||
assert.strictEqual(1024, metadata.width);
|
assert.strictEqual(1024, metadata.width);
|
||||||
@ -134,8 +133,8 @@ describe('Image metadata', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.gif.input.file) {
|
if (sharp.format.gif.input.file) {
|
||||||
it('GIF via giflib', function(done) {
|
it('GIF via giflib', function (done) {
|
||||||
sharp(fixtures.inputGif).metadata(function(err, metadata) {
|
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('gif', metadata.format);
|
assert.strictEqual('gif', metadata.format);
|
||||||
assert.strictEqual(800, metadata.width);
|
assert.strictEqual(800, metadata.width);
|
||||||
@ -150,8 +149,8 @@ describe('Image metadata', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('GIF grey+alpha via giflib', function(done) {
|
it('GIF grey+alpha via giflib', function (done) {
|
||||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function(err, metadata) {
|
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('gif', metadata.format);
|
assert.strictEqual('gif', metadata.format);
|
||||||
assert.strictEqual(2, metadata.width);
|
assert.strictEqual(2, metadata.width);
|
||||||
@ -169,8 +168,8 @@ describe('Image metadata', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.openslide.input.file) {
|
if (sharp.format.openslide.input.file) {
|
||||||
it('Aperio SVS via openslide', function(done) {
|
it('Aperio SVS via openslide', function (done) {
|
||||||
sharp(fixtures.inputSvs).metadata(function(err, metadata) {
|
sharp(fixtures.inputSvs).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('openslide', metadata.format);
|
assert.strictEqual('openslide', metadata.format);
|
||||||
assert.strictEqual(2220, metadata.width);
|
assert.strictEqual(2220, metadata.width);
|
||||||
@ -188,8 +187,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('File in, Promise out', function(done) {
|
it('File in, Promise out', function (done) {
|
||||||
sharp(fixtures.inputJpg).metadata().then(function(metadata) {
|
sharp(fixtures.inputJpg).metadata().then(function (metadata) {
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual(2725, metadata.width);
|
assert.strictEqual(2725, metadata.width);
|
||||||
assert.strictEqual(2225, metadata.height);
|
assert.strictEqual(2225, metadata.height);
|
||||||
@ -205,8 +204,8 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-existent file in, Promise out', function(done) {
|
it('Non-existent file in, Promise out', function (done) {
|
||||||
sharp('fail').metadata().then(function(metadata) {
|
sharp('fail').metadata().then(function (metadata) {
|
||||||
throw new Error('Non-existent file');
|
throw new Error('Non-existent file');
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
assert.ok(!!err);
|
assert.ok(!!err);
|
||||||
@ -214,10 +213,10 @@ 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);
|
||||||
assert.strictEqual(2225, metadata.height);
|
assert.strictEqual(2225, metadata.height);
|
||||||
@ -230,15 +229,15 @@ describe('Image metadata', function() {
|
|||||||
assert.strictEqual('undefined', typeof metadata.exif);
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
assert.strictEqual('undefined', typeof metadata.icc);
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
done();
|
done();
|
||||||
}).catch(function(err) {
|
}).catch(function (err) {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
@ -256,9 +255,9 @@ describe('Image metadata', function() {
|
|||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
assert.strictEqual(2725, metadata.width);
|
assert.strictEqual(2725, metadata.width);
|
||||||
@ -271,7 +270,7 @@ describe('Image metadata', function() {
|
|||||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||||
assert.strictEqual('undefined', typeof metadata.exif);
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
assert.strictEqual('undefined', typeof metadata.icc);
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
image.resize(Math.floor(metadata.width / 2)).toBuffer(function(err, data, info) {
|
image.resize(Math.floor(metadata.width / 2)).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(1362, info.width);
|
assert.strictEqual(1362, info.width);
|
||||||
@ -281,27 +280,27 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keep EXIF metadata and add sRGB profile after a resize', function(done) {
|
it('Keep EXIF metadata and add sRGB profile after a resize', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(buffer).metadata(function(err, metadata) {
|
sharp(buffer).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, metadata.hasProfile);
|
assert.strictEqual(true, metadata.hasProfile);
|
||||||
assert.strictEqual(8, metadata.orientation);
|
assert.strictEqual(8, metadata.orientation);
|
||||||
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);
|
||||||
@ -311,13 +310,13 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Remove EXIF metadata after a resize', function(done) {
|
it('Remove EXIF metadata after a resize', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withMetadata(false)
|
.withMetadata(false)
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(buffer).metadata(function(err, metadata) {
|
sharp(buffer).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||||
@ -328,12 +327,12 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Remove metadata from PNG output', function(done) {
|
it('Remove metadata from PNG output', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer(function(err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(buffer).metadata(function(err, metadata) {
|
sharp(buffer).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||||
@ -344,30 +343,30 @@ describe('Image metadata', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('File input with corrupt header fails gracefully', function(done) {
|
it('File input with corrupt header fails gracefully', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.metadata(function(err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Buffer input with corrupt header fails gracefully', function(done) {
|
it('Buffer input with corrupt header fails gracefully', function (done) {
|
||||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||||
.metadata(function(err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid withMetadata parameters', function() {
|
describe('Invalid withMetadata parameters', function () {
|
||||||
it('String orientation', function() {
|
it('String orientation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().withMetadata({orientation: 'zoinks'});
|
sharp().withMetadata({orientation: 'zoinks'});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Negative orientation', function() {
|
it('Negative orientation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().withMetadata({orientation: -1});
|
sharp().withMetadata({orientation: -1});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -376,8 +375,8 @@ describe('Image metadata', function() {
|
|||||||
sharp().withMetadata({ orientation: 0 });
|
sharp().withMetadata({ orientation: 0 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Too large orientation', function() {
|
it('Too large orientation', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().withMetadata({orientation: 9});
|
sharp().withMetadata({orientation: 9});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,105 +1,110 @@
|
|||||||
'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) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual('jpeg', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('negate (png)', function(done) {
|
it('negate (png)', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual('png', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate.png'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
fixtures.assertSimilar(fixtures.expected('negate.png'), data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('negate (png, trans)', function(done) {
|
it('negate (png, trans)', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual('png', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('negate (png, alpha)', function(done) {
|
it('negate (png, alpha)', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual('png', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.output.file) {
|
it('negate (webp)', function (done) {
|
||||||
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);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done);
|
fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (webp, trans)', function(done) {
|
it('negate (webp, trans)', function (done) {
|
||||||
sharp(fixtures.inputWebPWithTransparency)
|
sharp(fixtures.inputWebPWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
assert.strictEqual('webp', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
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) {
|
||||||
assert.strictEqual('jpeg', info.format);
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(320, info.width);
|
||||||
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
assert.strictEqual(240, info.height);
|
||||||
});
|
fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
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,12 +17,11 @@ 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('spreads rgb image values between 0 and 255', function(done) {
|
it('spreads rgb image values between 0 and 255', function (done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.normalize()
|
.normalize()
|
||||||
.raw()
|
.raw()
|
||||||
@ -33,7 +32,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('spreads grayscaled image values between 0 and 255', function(done) {
|
it('spreads grayscaled image values between 0 and 255', function (done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.gamma()
|
.gamma()
|
||||||
.greyscale()
|
.greyscale()
|
||||||
@ -46,7 +45,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stretches greyscale images with alpha channel', function(done) {
|
it('stretches greyscale images with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.normalize()
|
.normalize()
|
||||||
.raw()
|
.raw()
|
||||||
@ -57,12 +56,12 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps an existing alpha channel', function(done) {
|
it('keeps an existing alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.normalize()
|
.normalize()
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(data).metadata(function(err, metadata) {
|
sharp(data).metadata(function (err, metadata) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
assert.strictEqual(4, metadata.channels);
|
assert.strictEqual(4, metadata.channels);
|
||||||
assert.strictEqual(true, metadata.hasAlpha);
|
assert.strictEqual(true, metadata.hasAlpha);
|
||||||
@ -72,12 +71,12 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps the alpha channel of greyscale images intact', function(done) {
|
it('keeps the alpha channel of greyscale images intact', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.normalize()
|
.normalize()
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(data).metadata(function(err, metadata) {
|
sharp(data).metadata(function (err, metadata) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
assert.strictEqual(true, metadata.hasAlpha);
|
assert.strictEqual(true, metadata.hasAlpha);
|
||||||
assert.strictEqual(4, metadata.channels);
|
assert.strictEqual(4, metadata.channels);
|
||||||
@ -87,18 +86,18 @@ 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) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with 16-bit RGBA images', function(done) {
|
it('works with 16-bit RGBA images', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.normalize()
|
.normalize()
|
||||||
.raw()
|
.raw()
|
||||||
@ -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)
|
||||||
@ -30,8 +31,8 @@ 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))
|
||||||
@ -42,8 +43,8 @@ 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)
|
||||||
@ -54,8 +55,8 @@ 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)
|
||||||
@ -71,8 +72,8 @@ 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)
|
||||||
@ -83,8 +84,8 @@ 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)
|
||||||
@ -95,8 +96,8 @@ 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)
|
||||||
@ -113,26 +114,26 @@ 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)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||||
.toFile(paths.actual, function(error, info) {
|
.toFile(paths.actual, function (error, info) {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
.overlayWith(fixtures.inputPngWithGreyAlpha)
|
.overlayWith(fixtures.inputPngWithGreyAlpha)
|
||||||
.toFile(paths.actual, function(error, info) {
|
.toFile(paths.actual, function (error, info) {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||||
done();
|
done();
|
||||||
@ -140,13 +141,13 @@ 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)
|
||||||
.overlayWith(fixtures.inputWebPWithTransparency)
|
.overlayWith(fixtures.inputWebPWithTransparency)
|
||||||
.toFile(paths.actual, function(error, info) {
|
.toFile(paths.actual, function (error, info) {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102);
|
||||||
done();
|
done();
|
||||||
@ -154,48 +155,48 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Composite JPEG onto PNG', function(done) {
|
it('Composite JPEG onto PNG', function (done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.toBuffer(function(error) {
|
.toBuffer(function (error) {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Composite opaque JPEG onto JPEG', function(done) {
|
it('Composite opaque JPEG onto JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
.overlayWith(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.toBuffer(function(error) {
|
.toBuffer(function (error) {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when overlay is larger', function(done) {
|
it('Fail when overlay is larger', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1)
|
.overlayWith(fixtures.inputPngOverlayLayer1)
|
||||||
.toBuffer(function(error) {
|
.toBuffer(function (error) {
|
||||||
assert.strictEqual(true, error instanceof Error);
|
assert.strictEqual(true, error instanceof Error);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail with empty String parameter', function() {
|
it('Fail with empty String parameter', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().overlayWith('');
|
sharp().overlayWith('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail with non-String parameter', function() {
|
it('Fail with non-String parameter', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().overlayWith(1);
|
sharp().overlayWith(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail with unsupported gravity', function() {
|
it('Fail with unsupported gravity', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp()
|
sharp()
|
||||||
.overlayWith(fixtures.inputPngOverlayLayer1, {
|
.overlayWith(fixtures.inputPngOverlayLayer1, {
|
||||||
gravity: 9
|
gravity: 9
|
||||||
@ -203,22 +204,22 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Empty options', function() {
|
it('Empty options', function () {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function () {
|
||||||
sharp().overlayWith(fixtures.inputPngOverlayLayer1, {});
|
sharp().overlayWith(fixtures.inputPngOverlayLayer1, {});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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, {
|
||||||
gravity: gravity
|
gravity: gravity
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -230,16 +231,16 @@ 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, {
|
||||||
gravity: sharp.gravity[gravity]
|
gravity: sharp.gravity[gravity]
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -251,17 +252,17 @@ 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, {
|
||||||
tile: true,
|
tile: true,
|
||||||
gravity: gravity
|
gravity: gravity
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -273,43 +274,41 @@ 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, {
|
||||||
top: 10,
|
top: 10,
|
||||||
left: 10
|
left: 10
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(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, {
|
||||||
top: 100,
|
top: 100,
|
||||||
left: 300
|
left: 300
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(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 () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
@ -318,84 +317,81 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with only left offset', function() {
|
it('Overlay with only left offset', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
left: 1000
|
left: 1000
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with negative offsets', function() {
|
it('Overlay with negative offsets', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(400)
|
.resize(400)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
top: -1000,
|
top: -1000,
|
||||||
left: -1000
|
left: -1000
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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, {
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0
|
left: 0
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(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, {
|
||||||
left: 10,
|
left: 10,
|
||||||
top: 10,
|
top: 10,
|
||||||
gravity : 4
|
gravity: 4
|
||||||
|
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(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, {
|
||||||
left: 10,
|
left: 10,
|
||||||
top: 10,
|
top: 10,
|
||||||
gravity : 4,
|
gravity: 4,
|
||||||
tile: true
|
tile: true
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(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, {
|
||||||
@ -403,7 +399,7 @@ describe('Overlays', function() {
|
|||||||
top: 10,
|
top: 10,
|
||||||
tile: true
|
tile: true
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -411,27 +407,27 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with invalid cutout option', function() {
|
it('Overlay with invalid cutout option', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().overlayWith('ignore', { cutout: 1 });
|
sharp().overlayWith('ignore', { cutout: 1 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay with invalid tile option', function() {
|
it('Overlay with invalid tile option', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().overlayWith('ignore', { tile: 1 });
|
sharp().overlayWith('ignore', { tile: 1 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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, {
|
||||||
left: 10000,
|
left: 10000,
|
||||||
top: 10000
|
top: 10000
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -439,10 +435,10 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overlay 100x100 with 50x50 so bottom edges meet', function(done) {
|
it('Overlay 100x100 with 50x50 so bottom edges meet', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(50, 50)
|
.resize(50, 50)
|
||||||
.toBuffer(function(err, overlay) {
|
.toBuffer(function (err, overlay) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.resize(100, 100)
|
.resize(100, 100)
|
||||||
@ -450,7 +446,7 @@ describe('Overlays', function() {
|
|||||||
top: 50,
|
top: 50,
|
||||||
left: 40
|
left: 40
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(100, info.width);
|
assert.strictEqual(100, info.width);
|
||||||
@ -461,15 +457,15 @@ 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)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
tile: true
|
tile: true
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -479,8 +475,8 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('With tile enabled and image rotated 90 degrees and gravity northwest', function(done) {
|
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)
|
||||||
@ -488,7 +484,7 @@ describe('Overlays', function() {
|
|||||||
tile: true,
|
tile: true,
|
||||||
gravity: 'northwest'
|
gravity: 'northwest'
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -498,17 +494,17 @@ 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, {
|
||||||
cutout: true,
|
cutout: true,
|
||||||
gravity: gravity
|
gravity: gravity
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -520,15 +516,15 @@ 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)
|
||||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||||
cutout: true
|
cutout: true
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -538,8 +534,8 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('With cutout enabled and image rotated 90 degrees and gravity northwest', function(done) {
|
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)
|
||||||
@ -547,7 +543,7 @@ describe('Overlays', function() {
|
|||||||
cutout: true,
|
cutout: true,
|
||||||
gravity: 'northwest'
|
gravity: 'northwest'
|
||||||
})
|
})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
@ -557,28 +553,27 @@ describe('Overlays', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Composite RGBA raw buffer onto JPEG', function(done) {
|
it('Composite RGBA raw buffer onto JPEG', function (done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(2048, 1536)
|
.resize(2048, 1536)
|
||||||
.overlayWith(data, { raw: info })
|
.overlayWith(data, { raw: info })
|
||||||
.toBuffer(function(err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
fixtures.assertSimilar(fixtures.expected('overlay-jpeg-with-rgb.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('overlay-jpeg-with-rgb.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Throws an error when called with an invalid file', function(done) {
|
it('Throws an error when called with an invalid file', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.overlayWith('notfound.png')
|
.overlayWith('notfound.png')
|
||||||
.toBuffer(function(err) {
|
.toBuffer(function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
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,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('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;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -18,8 +17,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fixed width', function(done) {
|
it('Fixed width', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -29,8 +28,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fixed height', function(done) {
|
it('Fixed height', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(null, 320).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -40,8 +39,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Identity transform', function(done) {
|
it('Identity transform', function (done) {
|
||||||
sharp(fixtures.inputJpg).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -51,8 +50,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Upscale', function(done) {
|
it('Upscale', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(3000).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(3000).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -62,8 +61,8 @@ 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) {
|
||||||
@ -73,8 +72,8 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@ -84,8 +83,8 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@ -95,8 +94,8 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@ -106,8 +105,8 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@ -117,8 +116,8 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@ -129,18 +128,18 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.output.buffer) {
|
if (sharp.format.webp.output.buffer) {
|
||||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function(done) {
|
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(1080, 607)
|
.resize(1080, 607)
|
||||||
.webp()
|
.webp()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(1080, info.width);
|
assert.strictEqual(1080, info.width);
|
||||||
assert.strictEqual(607, info.height);
|
assert.strictEqual(607, info.height);
|
||||||
sharp(data)
|
sharp(data)
|
||||||
.resize(233, 131)
|
.resize(233, 131)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(233, info.width);
|
assert.strictEqual(233, info.width);
|
||||||
@ -152,12 +151,12 @@ describe('Resize dimensions', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sharp.format.tiff.input.file) {
|
if (sharp.format.tiff.input.file) {
|
||||||
it('TIFF embed known to cause rounding errors', function(done) {
|
it('TIFF embed known to cause rounding errors', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(240, 320)
|
.resize(240, 320)
|
||||||
.embed()
|
.embed()
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -167,11 +166,11 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF known to cause rounding errors', function(done) {
|
it('TIFF known to cause rounding errors', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(240, 320)
|
.resize(240, 320)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -181,8 +180,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Max width or height considering ratio (portrait)', function(done) {
|
it('Max width or height considering ratio (portrait)', function (done) {
|
||||||
sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -192,8 +191,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Min width or height considering ratio (portrait)', function(done) {
|
it('Min width or height considering ratio (portrait)', function (done) {
|
||||||
sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -204,8 +203,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Max width or height considering ratio (landscape)', function(done) {
|
it('Max width or height considering ratio (landscape)', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 320).max().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320, 320).max().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -215,8 +214,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Provide only one dimension with max, should default to crop', function(done) {
|
it('Provide only one dimension with max, should default to crop', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320).max().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320).max().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -226,8 +225,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Min width or height considering ratio (landscape)', function(done) {
|
it('Min width or height considering ratio (landscape)', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 320).min().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320, 320).min().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -237,8 +236,8 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Provide only one dimension with min, should default to crop', function(done) {
|
it('Provide only one dimension with min, should default to crop', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320).min().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320).min().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -248,11 +247,11 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not enlarge when input width is already less than output width', function(done) {
|
it('Do not enlarge when input width is already less than output width', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(2800)
|
.resize(2800)
|
||||||
.withoutEnlargement()
|
.withoutEnlargement()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -262,11 +261,11 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not enlarge when input height is already less than output height', function(done) {
|
it('Do not enlarge when input height is already less than output height', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(null, 2300)
|
.resize(null, 2300)
|
||||||
.withoutEnlargement()
|
.withoutEnlargement()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -276,11 +275,11 @@ describe('Resize dimensions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do enlarge when input width is less than output width', function(done) {
|
it('Do enlarge when input width is less than output width', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(2800)
|
.resize(2800)
|
||||||
.withoutEnlargement(false)
|
.withoutEnlargement(false)
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -289,9 +288,9 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Downscale width and height, ignoring aspect ratio', function(done) {
|
it('Downscale width and height, ignoring aspect ratio', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -300,9 +299,9 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Downscale width, ignoring aspect ratio', function(done) {
|
it('Downscale width, ignoring aspect ratio', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -311,82 +310,81 @@ describe('Resize dimensions', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Downscale height, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(2725, info.width);
|
|
||||||
assert.strictEqual(320, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Upscale width and height, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(3000, info.width);
|
|
||||||
assert.strictEqual(3000, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Upscale width, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(3000, info.width);
|
|
||||||
assert.strictEqual(2225, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Upscale height, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(2725, info.width);
|
|
||||||
assert.strictEqual(3000, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Downscale width, upscale height, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(320, info.width);
|
|
||||||
assert.strictEqual(3000, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Upscale width, downscale height, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(3000, info.width);
|
|
||||||
assert.strictEqual(320, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Identity transform, ignoring aspect ratio', function(done) {
|
|
||||||
sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function(err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(2725, info.width);
|
|
||||||
assert.strictEqual(2225, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
it('Downscale height, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(320, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Upscale width and height, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(3000, info.width);
|
||||||
|
assert.strictEqual(3000, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Upscale width, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(3000, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Upscale height, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(3000, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Downscale width, upscale height, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(3000, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Upscale width, downscale height, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(3000, info.width);
|
||||||
|
assert.strictEqual(320, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Identity transform, ignoring aspect ratio', function (done) {
|
||||||
|
sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
'use strict';
|
'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) {
|
sharp(fixtures['inputJpgWith' + orientation + 'Exif' + exifTag])
|
||||||
sharp(fixtures['inputJpgWith'+orientation+'Exif'+exifTag])
|
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -24,8 +23,8 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 90 degrees, respecting output input size', function(done) {
|
it('Rotate by 90 degrees, respecting output input size', function (done) {
|
||||||
sharp(fixtures.inputJpg).rotate(90).resize(320, 240).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).rotate(90).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -35,16 +34,17 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function(done) {
|
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(240, 240)
|
.resize(240, 240)
|
||||||
.ignoreAspectRatio()
|
.ignoreAspectRatio()
|
||||||
.rotate(270)
|
.rotate(270)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
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();
|
||||||
@ -52,16 +52,17 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function(done) {
|
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.ignoreAspectRatio()
|
.ignoreAspectRatio()
|
||||||
.rotate(270)
|
.rotate(270)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(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();
|
||||||
@ -69,28 +70,29 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag but do not rotate output', function(done) {
|
it('Input image has Orientation EXIF tag but do not rotate output', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function(done) {
|
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -99,42 +101,44 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Override EXIF Orientation tag metadata after auto-rotate', function(done) {
|
it('Override EXIF Orientation tag metadata after auto-rotate', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.withMetadata({orientation: 3})
|
.withMetadata({orientation: 3})
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function(done) {
|
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (done) {
|
||||||
sharp(fixtures.inputJpgWithExifMirroring)
|
sharp(fixtures.inputJpgWithExifMirroring)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Attempt to auto-rotate using image that has no EXIF', function(done) {
|
it('Attempt to auto-rotate using image that has no EXIF', function (done) {
|
||||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function(err, data, info) {
|
sharp(fixtures.inputJpg).rotate().resize(320).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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -144,12 +148,12 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Attempt to auto-rotate image format without EXIF support', function(done) {
|
it('Attempt to auto-rotate image format without EXIF support', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function(err, data, info) {
|
.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('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -159,23 +163,23 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate to an invalid angle, should fail', function() {
|
it('Rotate to an invalid angle, should fail', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).rotate(1);
|
sharp(fixtures.inputJpg).rotate(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flip - vertical', function(done) {
|
it('Flip - vertical', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip()
|
.flip()
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
sharp(data).metadata(function(err, metadata) {
|
sharp(data).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(1, metadata.orientation);
|
assert.strictEqual(1, metadata.orientation);
|
||||||
fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done);
|
||||||
@ -183,17 +187,17 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flop - horizontal', function(done) {
|
it('Flop - horizontal', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flop()
|
.flop()
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(261, info.height);
|
assert.strictEqual(261, info.height);
|
||||||
sharp(data).metadata(function(err, metadata) {
|
sharp(data).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(1, metadata.orientation);
|
assert.strictEqual(1, metadata.orientation);
|
||||||
fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done);
|
||||||
@ -201,11 +205,11 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flip and flop', function(done) {
|
it('Flip and flop', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flop()
|
.flop()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -214,12 +218,12 @@ describe('Rotation', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Neither flip nor flop', function(done) {
|
it('Neither flip nor flop', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip(false)
|
.flip(false)
|
||||||
.flop(false)
|
.flop(false)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -227,5 +231,4 @@ describe('Rotation', function() {
|
|||||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,17 +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('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)
|
||||||
.sharpen(6)
|
.sharpen(6)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -20,11 +19,11 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function(done) {
|
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(1.5, 0.5, 2.5)
|
.sharpen(1.5, 0.5, 2.5)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -33,11 +32,11 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', function(done) {
|
it('specific radius 5 (sigma 3.5) and levels 2, 4', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(3.5, 2, 4)
|
.sharpen(3.5, 2, 4)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -47,11 +46,11 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
||||||
it('specific radius/levels with alpha channel', function(done) {
|
it('specific radius/levels with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(5, 4, 8)
|
.sharpen(5, 4, 8)
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
@ -62,11 +61,11 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('mild sharpen', function(done) {
|
it('mild sharpen', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen()
|
.sharpen()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -75,29 +74,29 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid sigma', function() {
|
it('invalid sigma', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).sharpen(-1.5);
|
sharp(fixtures.inputJpg).sharpen(-1.5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid flat', function() {
|
it('invalid flat', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).sharpen(1, -1);
|
sharp(fixtures.inputJpg).sharpen(1, -1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid jagged', function() {
|
it('invalid jagged', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg).sharpen(1, 1, -1);
|
sharp(fixtures.inputJpg).sharpen(1, 1, -1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sharpened image is larger than non-sharpened', function(done) {
|
it('sharpened image is larger than non-sharpened', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(false)
|
.sharpen(false)
|
||||||
.toBuffer(function(err, notSharpened, info) {
|
.toBuffer(function (err, notSharpened, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, notSharpened.length > 0);
|
assert.strictEqual(true, notSharpened.length > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -106,7 +105,7 @@ describe('Sharpen', function() {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(true)
|
.sharpen(true)
|
||||||
.toBuffer(function(err, sharpened, info) {
|
.toBuffer(function (err, sharpened, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, sharpened.length > 0);
|
assert.strictEqual(true, sharpened.length > 0);
|
||||||
assert.strictEqual(true, sharpened.length > notSharpened.length);
|
assert.strictEqual(true, sharpened.length > notSharpened.length);
|
||||||
@ -117,5 +116,4 @@ describe('Sharpen', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,16 +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('Threshold', function() {
|
describe('Threshold', function () {
|
||||||
it('threshold 1 jpeg', function(done) {
|
it('threshold 1 jpeg', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -18,11 +19,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold 40 jpeg', function(done) {
|
it('threshold 40 jpeg', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -30,11 +32,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold 128', function(done) {
|
it('threshold 128', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -42,11 +45,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold true (=128)', function(done) {
|
it('threshold true (=128)', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -54,19 +58,21 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold false (=0)', function(done) {
|
it('threshold false (=0)', function (done) {
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold grayscale: true (=128)', function(done) {
|
it('threshold grayscale: true (=128)', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -74,11 +80,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default jpeg', function(done) {
|
it('threshold default jpeg', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.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);
|
||||||
@ -86,11 +93,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default png transparency', function(done) {
|
it('threshold default png transparency', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.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);
|
||||||
@ -98,11 +106,12 @@ describe('Threshold', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default png alpha', function(done) {
|
it('threshold default png alpha', function (done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.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,37 +119,37 @@ 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);
|
||||||
fixtures.assertSimilar(fixtures.expected('threshold-color-128.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('threshold-color-128.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid threshold -1', function() {
|
it('invalid threshold -1', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().threshold(-1);
|
sharp().threshold(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalid threshold 256', function() {
|
it('invalid threshold 256', function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().threshold(256);
|
sharp().threshold(256);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,18 +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('Trim borders', function() {
|
describe('Trim borders', function () {
|
||||||
|
it('Threshold default', function (done) {
|
||||||
it('Threshold default', function(done) {
|
const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
||||||
var expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
|
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(450, 322)
|
.resize(450, 322)
|
||||||
.trim()
|
.trim()
|
||||||
.toBuffer(function(err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(450, info.width);
|
assert.strictEqual(450, info.width);
|
||||||
@ -21,11 +20,11 @@ describe('Trim borders', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel', function(done) {
|
it('16-bit PNG with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 32)
|
.resize(32, 32)
|
||||||
.trim(20)
|
.trim(20)
|
||||||
.toBuffer(function(err, data, info) {
|
.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('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -36,10 +35,10 @@ describe('Trim borders', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid thresholds', function() {
|
describe('Invalid thresholds', function () {
|
||||||
[-1, 100, 'fail', {}].forEach(function(threshold) {
|
[-1, 100, 'fail', {}].forEach(function (threshold) {
|
||||||
it(JSON.stringify(threshold), function() {
|
it(JSON.stringify(threshold), function () {
|
||||||
assert.throws(function() {
|
assert.throws(function () {
|
||||||
sharp().trim(threshold);
|
sharp().trim(threshold);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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');
|
||||||
@ -20,14 +18,14 @@ describe('Utilities', function() {
|
|||||||
assert.strictEqual(cache.items.current, 0);
|
assert.strictEqual(cache.items.current, 0);
|
||||||
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
|
||||||
@ -36,71 +34,71 @@ describe('Utilities', function() {
|
|||||||
assert.strictEqual(cache.files.max, 0);
|
assert.strictEqual(cache.files.max, 0);
|
||||||
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
|
||||||
});
|
});
|
||||||
assert.strictEqual(cache.memory.max, 10);
|
assert.strictEqual(cache.memory.max, 10);
|
||||||
assert.strictEqual(cache.files.max, 100);
|
assert.strictEqual(cache.files.max, 100);
|
||||||
assert.strictEqual(cache.items.max, 1000);
|
assert.strictEqual(cache.items.max, 1000);
|
||||||
});
|
});
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Concurrency', function() {
|
describe('Concurrency', function () {
|
||||||
it('Can be set to use 16 threads', function() {
|
it('Can be set to use 16 threads', function () {
|
||||||
sharp.concurrency(16);
|
sharp.concurrency(16);
|
||||||
assert.strictEqual(16, sharp.concurrency());
|
assert.strictEqual(16, sharp.concurrency());
|
||||||
});
|
});
|
||||||
it('Can be reset to default', function() {
|
it('Can be reset to default', function () {
|
||||||
sharp.concurrency(0);
|
sharp.concurrency(0);
|
||||||
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
||||||
});
|
});
|
||||||
it('Ignores invalid values', function() {
|
it('Ignores invalid values', function () {
|
||||||
sharp.concurrency(0);
|
sharp.concurrency(0);
|
||||||
sharp.concurrency('spoons');
|
sharp.concurrency('spoons');
|
||||||
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Format', function() {
|
describe('Format', function () {
|
||||||
it('Contains expected attributes', function() {
|
it('Contains expected attributes', function () {
|
||||||
assert.strictEqual('object', typeof sharp.format);
|
assert.strictEqual('object', typeof sharp.format);
|
||||||
Object.keys(sharp.format).forEach(function(format) {
|
Object.keys(sharp.format).forEach(function (format) {
|
||||||
assert.strictEqual(true, 'id' in sharp.format[format]);
|
assert.strictEqual(true, 'id' in sharp.format[format]);
|
||||||
assert.strictEqual(format, sharp.format[format].id);
|
assert.strictEqual(format, sharp.format[format].id);
|
||||||
['input', 'output'].forEach(function(direction) {
|
['input', 'output'].forEach(function (direction) {
|
||||||
assert.strictEqual(true, direction in sharp.format[format]);
|
assert.strictEqual(true, direction in sharp.format[format]);
|
||||||
assert.strictEqual('object', typeof sharp.format[format][direction]);
|
assert.strictEqual('object', typeof sharp.format[format][direction]);
|
||||||
assert.strictEqual(3, Object.keys(sharp.format[format][direction]).length);
|
assert.strictEqual(3, Object.keys(sharp.format[format][direction]).length);
|
||||||
@ -113,8 +111,8 @@ describe('Utilities', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Raw file=false, buffer=true, stream=true', function() {
|
it('Raw file=false, buffer=true, stream=true', function () {
|
||||||
['input', 'output'].forEach(function(direction) {
|
['input', 'output'].forEach(function (direction) {
|
||||||
assert.strictEqual(false, sharp.format.raw[direction].file);
|
assert.strictEqual(false, sharp.format.raw[direction].file);
|
||||||
assert.strictEqual(true, sharp.format.raw[direction].buffer);
|
assert.strictEqual(true, sharp.format.raw[direction].buffer);
|
||||||
assert.strictEqual(true, sharp.format.raw[direction].stream);
|
assert.strictEqual(true, sharp.format.raw[direction].stream);
|
||||||
@ -122,11 +120,10 @@ describe('Utilities', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Versions', function() {
|
describe('Versions', function () {
|
||||||
it('Contains expected attributes', function() {
|
it('Contains expected attributes', function () {
|
||||||
assert.strictEqual('object', typeof sharp.versions);
|
assert.strictEqual('object', typeof sharp.versions);
|
||||||
assert.strictEqual('string', typeof sharp.versions.vips);
|
assert.strictEqual('string', typeof sharp.versions.vips);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user