mirror of
https://github.com/lovell/sharp.git
synced 2025-12-06 03:51:40 +01:00
Linter: apply all recommended biome settings
Enforces previously-skipped useArrowFunction check
This commit is contained in:
parent
09d5aa8cfa
commit
4f9f8179a6
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.3.2/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
@ -11,10 +11,7 @@
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"complexity": {
|
||||
"useArrowFunction": "off"
|
||||
}
|
||||
"recommended": true
|
||||
}
|
||||
},
|
||||
"formatter": {
|
||||
|
||||
@ -163,7 +163,7 @@ function bandbool (boolOp) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Public instance functions
|
||||
removeAlpha,
|
||||
|
||||
@ -175,7 +175,7 @@ function _setBackgroundColourOption (key, value) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Public
|
||||
tint,
|
||||
|
||||
@ -206,7 +206,7 @@ function composite (images) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Sharp.prototype.composite = composite;
|
||||
Sharp.blend = blend;
|
||||
};
|
||||
|
||||
@ -12,6 +12,10 @@ require('./sharp');
|
||||
// Use NODE_DEBUG=sharp to enable libvips warnings
|
||||
const debuglog = util.debuglog('sharp');
|
||||
|
||||
const queueListener = (queueLength) => {
|
||||
Sharp.queue.emit('change', queueLength);
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||
*
|
||||
@ -398,9 +402,7 @@ const Sharp = function (input, options) {
|
||||
debuglog(warning);
|
||||
},
|
||||
// Function to notify of queue length changes
|
||||
queueListener: function (queueLength) {
|
||||
Sharp.queue.emit('change', queueLength);
|
||||
}
|
||||
queueListener
|
||||
};
|
||||
this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
|
||||
return this;
|
||||
|
||||
@ -792,7 +792,7 @@ function stats (callback) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Private
|
||||
_inputOptionsFromObject,
|
||||
|
||||
56
lib/is.js
56
lib/is.js
@ -7,55 +7,43 @@
|
||||
* Is this value defined and not null?
|
||||
* @private
|
||||
*/
|
||||
const defined = function (val) {
|
||||
return typeof val !== 'undefined' && val !== null;
|
||||
};
|
||||
const defined = (val) => typeof val !== 'undefined' && val !== null;
|
||||
|
||||
/**
|
||||
* Is this value an object?
|
||||
* @private
|
||||
*/
|
||||
const object = function (val) {
|
||||
return typeof val === 'object';
|
||||
};
|
||||
const object = (val) => typeof val === 'object';
|
||||
|
||||
/**
|
||||
* Is this value a plain object?
|
||||
* @private
|
||||
*/
|
||||
const plainObject = function (val) {
|
||||
return Object.prototype.toString.call(val) === '[object Object]';
|
||||
};
|
||||
const plainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
|
||||
|
||||
/**
|
||||
* Is this value a function?
|
||||
* @private
|
||||
*/
|
||||
const fn = function (val) {
|
||||
return typeof val === 'function';
|
||||
};
|
||||
const fn = (val) => typeof val === 'function';
|
||||
|
||||
/**
|
||||
* Is this value a boolean?
|
||||
* @private
|
||||
*/
|
||||
const bool = function (val) {
|
||||
return typeof val === 'boolean';
|
||||
};
|
||||
const bool = (val) => typeof val === 'boolean';
|
||||
|
||||
/**
|
||||
* Is this value a Buffer object?
|
||||
* @private
|
||||
*/
|
||||
const buffer = function (val) {
|
||||
return val instanceof Buffer;
|
||||
};
|
||||
const buffer = (val) => val instanceof Buffer;
|
||||
|
||||
/**
|
||||
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
||||
* @private
|
||||
*/
|
||||
const typedArray = function (val) {
|
||||
const typedArray = (val) => {
|
||||
if (defined(val)) {
|
||||
switch (val.constructor) {
|
||||
case Uint8Array:
|
||||
@ -78,49 +66,37 @@ const typedArray = function (val) {
|
||||
* Is this value an ArrayBuffer object?
|
||||
* @private
|
||||
*/
|
||||
const arrayBuffer = function (val) {
|
||||
return val instanceof ArrayBuffer;
|
||||
};
|
||||
const arrayBuffer = (val) => val instanceof ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Is this value a non-empty string?
|
||||
* @private
|
||||
*/
|
||||
const string = function (val) {
|
||||
return typeof val === 'string' && val.length > 0;
|
||||
};
|
||||
const string = (val) => typeof val === 'string' && val.length > 0;
|
||||
|
||||
/**
|
||||
* Is this value a real number?
|
||||
* @private
|
||||
*/
|
||||
const number = function (val) {
|
||||
return typeof val === 'number' && !Number.isNaN(val);
|
||||
};
|
||||
const number = (val) => typeof val === 'number' && !Number.isNaN(val);
|
||||
|
||||
/**
|
||||
* Is this value an integer?
|
||||
* @private
|
||||
*/
|
||||
const integer = function (val) {
|
||||
return Number.isInteger(val);
|
||||
};
|
||||
const integer = (val) => Number.isInteger(val);
|
||||
|
||||
/**
|
||||
* Is this value within an inclusive given range?
|
||||
* @private
|
||||
*/
|
||||
const inRange = function (val, min, max) {
|
||||
return val >= min && val <= max;
|
||||
};
|
||||
const inRange = (val, min, max) => val >= min && val <= max;
|
||||
|
||||
/**
|
||||
* Is this value within the elements of an array?
|
||||
* @private
|
||||
*/
|
||||
const inArray = function (val, list) {
|
||||
return list.includes(val);
|
||||
};
|
||||
const inArray = (val, list) => list.includes(val);
|
||||
|
||||
/**
|
||||
* Create an Error with a message relating to an invalid parameter.
|
||||
@ -131,11 +107,9 @@ const inArray = function (val, list) {
|
||||
* @returns {Error} Containing the formatted message.
|
||||
* @private
|
||||
*/
|
||||
const invalidParameterError = function (name, expected, actual) {
|
||||
return new Error(
|
||||
const invalidParameterError = (name, expected, actual) => new Error(
|
||||
`Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensures an Error from C++ contains a JS stack.
|
||||
@ -145,7 +119,7 @@ const invalidParameterError = function (name, expected, actual) {
|
||||
* @returns {Error} Error with message and stack.
|
||||
* @private
|
||||
*/
|
||||
const nativeError = function (native, context) {
|
||||
const nativeError = (native, context) => {
|
||||
context.message = native.message;
|
||||
return context;
|
||||
};
|
||||
|
||||
@ -742,9 +742,7 @@ function convolve (kernel) {
|
||||
}
|
||||
// Default scale is sum of kernel values
|
||||
if (!is.integer(kernel.scale)) {
|
||||
kernel.scale = kernel.kernel.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}, 0);
|
||||
kernel.scale = kernel.kernel.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
// Clip scale to a minimum value of 1
|
||||
if (kernel.scale < 1) {
|
||||
@ -989,7 +987,7 @@ function modulate (options) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
autoOrient,
|
||||
rotate,
|
||||
|
||||
@ -1623,7 +1623,7 @@ function _pipeline (callback, stack) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Public
|
||||
toFile,
|
||||
|
||||
@ -579,7 +579,7 @@ function trim (options) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Object.assign(Sharp.prototype, {
|
||||
resize,
|
||||
extend,
|
||||
|
||||
@ -277,7 +277,7 @@ function unblock (options) {
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
module.exports = (Sharp) => {
|
||||
Sharp.cache = cache;
|
||||
Sharp.concurrency = concurrency;
|
||||
Sharp.counters = counters;
|
||||
|
||||
@ -170,7 +170,7 @@
|
||||
"@img/sharp-win32-x64": "0.34.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.2",
|
||||
"@biomejs/biome": "^2.3.3",
|
||||
"@cpplint/cli": "^0.1.0",
|
||||
"@emnapi/runtime": "^1.6.0",
|
||||
"@img/sharp-libvips-dev": "1.2.4",
|
||||
|
||||
@ -16,31 +16,29 @@ const height = 480;
|
||||
|
||||
sharp.concurrency(1);
|
||||
|
||||
const timer = setInterval(function () {
|
||||
const timer = setInterval(() => {
|
||||
console.dir(sharp.counters());
|
||||
}, 100);
|
||||
|
||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], (parallelism, next) => {
|
||||
const start = Date.now();
|
||||
async.times(parallelism,
|
||||
function (_id, callback) {
|
||||
sharp(fixtures.inputJpg).resize(width, height).toBuffer(function (err, buffer) {
|
||||
(_id, callback) => {
|
||||
sharp(fixtures.inputJpg).resize(width, height).toBuffer((err, buffer) => {
|
||||
buffer = null;
|
||||
callback(err, Date.now() - start);
|
||||
});
|
||||
},
|
||||
function (err, ids) {
|
||||
(err, ids) => {
|
||||
assert(!err);
|
||||
assert(ids.length === parallelism);
|
||||
ids.sort();
|
||||
const mean = ids.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}) / ids.length;
|
||||
const mean = ids.reduce((a, b) => a + b) / ids.length;
|
||||
console.log(`${parallelism} parallel calls: fastest=${ids[0]}ms slowest=${ids[ids.length - 1]}ms mean=${mean}ms`);
|
||||
next();
|
||||
}
|
||||
);
|
||||
}, function () {
|
||||
}, () => {
|
||||
clearInterval(timer);
|
||||
console.dir(sharp.counters());
|
||||
});
|
||||
|
||||
@ -45,13 +45,13 @@ console.log(`Detected ${physicalCores} physical cores`);
|
||||
sharp.concurrency(physicalCores);
|
||||
|
||||
async.series({
|
||||
jpeg: function (callback) {
|
||||
jpeg: (callback) => {
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const jpegSuite = new Benchmark.Suite('jpeg');
|
||||
// jimp
|
||||
jpegSuite.add('jimp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: async function (deferred) {
|
||||
fn: async (deferred) => {
|
||||
const image = await Jimp.read(inputJpgBuffer);
|
||||
await image
|
||||
.resize({ w: width, h: height, mode: Jimp.RESIZE_BICUBIC })
|
||||
@ -60,7 +60,7 @@ async.series({
|
||||
}
|
||||
}).add('jimp-file-file', {
|
||||
defer: true,
|
||||
fn: async function (deferred) {
|
||||
fn: async (deferred) => {
|
||||
const image = await Jimp.read(fixtures.inputJpg);
|
||||
await image
|
||||
.resize({ w: width, h: height, mode: Jimp.RESIZE_BICUBIC })
|
||||
@ -71,14 +71,14 @@ async.series({
|
||||
// mapnik
|
||||
mapnik && jpegSuite.add('mapnik-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
mapnik.Image.open(fixtures.inputJpg, function (err, img) {
|
||||
fn: (deferred) => {
|
||||
mapnik.Image.open(fixtures.inputJpg, (err, img) => {
|
||||
if (err) throw err;
|
||||
img
|
||||
.resize(width, height, {
|
||||
scaling_method: mapnik.imageScaling.lanczos
|
||||
})
|
||||
.save(outputJpg, 'jpeg:quality=80', function (err) {
|
||||
.save(outputJpg, 'jpeg:quality=80', (err) => {
|
||||
if (err) throw err;
|
||||
deferred.resolve();
|
||||
});
|
||||
@ -86,14 +86,14 @@ async.series({
|
||||
}
|
||||
}).add('mapnik-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
mapnik.Image.fromBytes(inputJpgBuffer, { max_size: 3000 }, function (err, img) {
|
||||
fn: (deferred) => {
|
||||
mapnik.Image.fromBytes(inputJpgBuffer, { max_size: 3000 }, (err, img) => {
|
||||
if (err) throw err;
|
||||
img
|
||||
.resize(width, height, {
|
||||
scaling_method: mapnik.imageScaling.lanczos
|
||||
})
|
||||
.encode('jpeg:quality=80', function (err) {
|
||||
.encode('jpeg:quality=80', (err) => {
|
||||
if (err) throw err;
|
||||
deferred.resolve();
|
||||
});
|
||||
@ -103,7 +103,7 @@ async.series({
|
||||
// imagemagick
|
||||
jpegSuite.add('imagemagick-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
imagemagick.resize({
|
||||
srcPath: fixtures.inputJpg,
|
||||
dstPath: outputJpg,
|
||||
@ -112,7 +112,7 @@ async.series({
|
||||
height,
|
||||
format: 'jpg',
|
||||
filter: 'Lanczos'
|
||||
}, function (err) {
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -124,12 +124,12 @@ async.series({
|
||||
// gm
|
||||
jpegSuite.add('gm-buffer-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(inputJpgBuffer)
|
||||
.filter('Lanczos')
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.write(outputJpg, function (err) {
|
||||
.write(outputJpg, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -139,12 +139,12 @@ async.series({
|
||||
}
|
||||
}).add('gm-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(inputJpgBuffer)
|
||||
.filter('Lanczos')
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -154,12 +154,12 @@ async.series({
|
||||
}
|
||||
}).add('gm-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(fixtures.inputJpg)
|
||||
.filter('Lanczos')
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.write(outputJpg, function (err) {
|
||||
.write(outputJpg, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -169,12 +169,12 @@ async.series({
|
||||
}
|
||||
}).add('gm-file-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(fixtures.inputJpg)
|
||||
.filter('Lanczos')
|
||||
.resize(width, height)
|
||||
.quality(80)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -186,17 +186,17 @@ async.series({
|
||||
// tfjs
|
||||
tfjs && jpegSuite.add('tfjs-node-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
const decoded = tfjs.node.decodeJpeg(inputJpgBuffer);
|
||||
const resized = tfjs.image.resizeBilinear(decoded, [height, width]);
|
||||
tfjs
|
||||
.node
|
||||
.encodeJpeg(resized, 'rgb', 80)
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
deferred.resolve();
|
||||
tfjs.disposeVariables();
|
||||
})
|
||||
.catch(function (err) {
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
@ -204,10 +204,10 @@ async.series({
|
||||
// sharp
|
||||
jpegSuite.add('sharp-buffer-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.toFile(outputJpg, function (err) {
|
||||
.toFile(outputJpg, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -217,10 +217,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -230,10 +230,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(width, height)
|
||||
.toFile(outputJpg, function (err) {
|
||||
.toFile(outputJpg, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -243,10 +243,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-stream-stream', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
writable.on('finish', function () {
|
||||
writable.on('finish', () => {
|
||||
deferred.resolve();
|
||||
});
|
||||
const pipeline = sharp()
|
||||
@ -255,10 +255,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-file-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -268,34 +268,34 @@ async.series({
|
||||
}
|
||||
}).add('sharp-promise', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.toBuffer()
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
deferred.resolve();
|
||||
})
|
||||
.catch(function (err) {
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
}).on('cycle', (event) => {
|
||||
console.log(`jpeg ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
},
|
||||
// Effect of applying operations
|
||||
operations: function (callback) {
|
||||
operations: (callback) => {
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const operationsSuite = new Benchmark.Suite('operations');
|
||||
operationsSuite.add('sharp-sharpen-mild', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.sharpen()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -305,11 +305,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-sharpen-radius', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.sharpen(3, 1, 3)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -319,11 +319,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-blur-mild', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.blur()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -333,11 +333,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-blur-radius', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.blur(3)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -347,11 +347,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-gamma', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.gamma()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -361,11 +361,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-normalise', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.normalise()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -375,11 +375,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-greyscale', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.greyscale()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -389,12 +389,12 @@ async.series({
|
||||
}
|
||||
}).add('sharp-greyscale-gamma', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.gamma()
|
||||
.greyscale()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -404,11 +404,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-progressive', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.jpeg({ progressive: true })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -418,11 +418,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-without-chroma-subsampling', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -432,11 +432,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-rotate', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.rotate(90)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -446,11 +446,11 @@ async.series({
|
||||
}
|
||||
}).add('sharp-without-simd', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp.simd(false);
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
sharp.simd(true);
|
||||
if (err) {
|
||||
throw err;
|
||||
@ -461,10 +461,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-random-access-read', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer, { sequentialRead: false })
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -474,13 +474,13 @@ async.series({
|
||||
}
|
||||
}).add('sharp-crop-entropy', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.entropy
|
||||
})
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -490,13 +490,13 @@ async.series({
|
||||
}
|
||||
}).add('sharp-crop-attention', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.attention
|
||||
})
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -504,21 +504,21 @@ async.series({
|
||||
}
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
}).on('cycle', (event) => {
|
||||
console.log(`operations ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
},
|
||||
// Comparative speed of kernels
|
||||
kernels: function (callback) {
|
||||
kernels: (callback) => {
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, { kernel: 'cubic' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -528,10 +528,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-lanczos2', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, { kernel: 'lanczos2' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -541,10 +541,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-lanczos3', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, { kernel: 'lanczos3' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -554,10 +554,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-mks2013', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, { kernel: 'mks2013' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -567,10 +567,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-mks2021', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputJpgBuffer)
|
||||
.resize(width, height, { kernel: 'mks2021' })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -578,21 +578,21 @@ async.series({
|
||||
}
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
}).on('cycle', (event) => {
|
||||
console.log(`kernels ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
},
|
||||
// PNG
|
||||
png: function (callback) {
|
||||
png: (callback) => {
|
||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPngAlphaPremultiplicationLarge);
|
||||
const pngSuite = new Benchmark.Suite('png');
|
||||
const minSamples = 64;
|
||||
// jimp
|
||||
pngSuite.add('jimp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: async function (deferred) {
|
||||
fn: async (deferred) => {
|
||||
const image = await Jimp.read(inputPngBuffer);
|
||||
await image
|
||||
.resize({ w: width, h: heightPng, mode: Jimp.RESIZE_BICUBIC })
|
||||
@ -601,7 +601,7 @@ async.series({
|
||||
}
|
||||
}).add('jimp-file-file', {
|
||||
defer: true,
|
||||
fn: async function (deferred) {
|
||||
fn: async (deferred) => {
|
||||
const image = await Jimp.read(fixtures.inputPngAlphaPremultiplicationLarge);
|
||||
await image
|
||||
.resize({ w: width, h: heightPng, mode: Jimp.RESIZE_BICUBIC })
|
||||
@ -612,18 +612,18 @@ async.series({
|
||||
// mapnik
|
||||
mapnik && pngSuite.add('mapnik-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
mapnik.Image.open(fixtures.inputPngAlphaPremultiplicationLarge, function (err, img) {
|
||||
fn: (deferred) => {
|
||||
mapnik.Image.open(fixtures.inputPngAlphaPremultiplicationLarge, (err, img) => {
|
||||
if (err) throw err;
|
||||
img.premultiply(function (err, img) {
|
||||
img.premultiply((err, img) => {
|
||||
if (err) throw err;
|
||||
img.resize(width, heightPng, {
|
||||
scaling_method: mapnik.imageScaling.lanczos
|
||||
}, function (err, img) {
|
||||
}, (err, img) => {
|
||||
if (err) throw err;
|
||||
img.demultiply(function (err, img) {
|
||||
img.demultiply((err, img) => {
|
||||
if (err) throw err;
|
||||
img.save(outputPng, 'png32:f=no:z=6', function (err) {
|
||||
img.save(outputPng, 'png32:f=no:z=6', (err) => {
|
||||
if (err) throw err;
|
||||
deferred.resolve();
|
||||
});
|
||||
@ -634,18 +634,18 @@ async.series({
|
||||
}
|
||||
}).add('mapnik-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
mapnik.Image.fromBytes(inputPngBuffer, { max_size: 3000 }, function (err, img) {
|
||||
fn: (deferred) => {
|
||||
mapnik.Image.fromBytes(inputPngBuffer, { max_size: 3000 }, (err, img) => {
|
||||
if (err) throw err;
|
||||
img.premultiply(function (err, img) {
|
||||
img.premultiply((err, img) => {
|
||||
if (err) throw err;
|
||||
img.resize(width, heightPng, {
|
||||
scaling_method: mapnik.imageScaling.lanczos
|
||||
}, function (err, img) {
|
||||
}, (err, img) => {
|
||||
if (err) throw err;
|
||||
img.demultiply(function (err, img) {
|
||||
img.demultiply((err, img) => {
|
||||
if (err) throw err;
|
||||
img.encode('png32:f=no:z=6', function (err) {
|
||||
img.encode('png32:f=no:z=6', (err) => {
|
||||
if (err) throw err;
|
||||
deferred.resolve();
|
||||
});
|
||||
@ -658,7 +658,7 @@ async.series({
|
||||
// imagemagick
|
||||
pngSuite.add('imagemagick-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
imagemagick.resize({
|
||||
srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
|
||||
dstPath: outputPng,
|
||||
@ -669,7 +669,7 @@ async.series({
|
||||
'-define', 'PNG:compression-level=6',
|
||||
'-define', 'PNG:compression-filter=0'
|
||||
]
|
||||
}, function (err) {
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -681,13 +681,13 @@ async.series({
|
||||
// gm
|
||||
pngSuite.add('gm-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.filter('Lanczos')
|
||||
.resize(width, heightPng)
|
||||
.define('PNG:compression-level=6')
|
||||
.define('PNG:compression-filter=0')
|
||||
.write(outputPng, function (err) {
|
||||
.write(outputPng, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -697,13 +697,13 @@ async.series({
|
||||
}
|
||||
}).add('gm-file-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.filter('Lanczos')
|
||||
.resize(width, heightPng)
|
||||
.define('PNG:compression-level=6')
|
||||
.define('PNG:compression-filter=0')
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -716,11 +716,11 @@ async.series({
|
||||
pngSuite.add('sharp-buffer-file', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6 })
|
||||
.toFile(outputPng, function (err) {
|
||||
.toFile(outputPng, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -731,11 +731,11 @@ async.series({
|
||||
}).add('sharp-buffer-buffer', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -746,11 +746,11 @@ async.series({
|
||||
}).add('sharp-file-file', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6 })
|
||||
.toFile(outputPng, function (err) {
|
||||
.toFile(outputPng, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -761,11 +761,11 @@ async.series({
|
||||
}).add('sharp-file-buffer', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -776,11 +776,11 @@ async.series({
|
||||
}).add('sharp-progressive', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 6, progressive: true })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -791,11 +791,11 @@ async.series({
|
||||
}).add('sharp-adaptiveFiltering', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ adaptiveFiltering: true, compressionLevel: 6 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -806,11 +806,11 @@ async.series({
|
||||
}).add('sharp-compressionLevel=9', {
|
||||
defer: true,
|
||||
minSamples,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputPngBuffer)
|
||||
.resize(width, heightPng)
|
||||
.png({ compressionLevel: 9 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -819,21 +819,21 @@ async.series({
|
||||
});
|
||||
}
|
||||
});
|
||||
pngSuite.on('cycle', function (event) {
|
||||
pngSuite.on('cycle', (event) => {
|
||||
console.log(` png ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
},
|
||||
// WebP
|
||||
webp: function (callback) {
|
||||
webp: (callback) => {
|
||||
const inputWebPBuffer = fs.readFileSync(fixtures.inputWebP);
|
||||
(new Benchmark.Suite('webp')).add('sharp-buffer-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputWebPBuffer)
|
||||
.resize(width, height)
|
||||
.toFile(outputWebP, function (err) {
|
||||
.toFile(outputWebP, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -843,10 +843,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-buffer-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(inputWebPBuffer)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -856,10 +856,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-file-file', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(width, height)
|
||||
.toFile(outputWebP, function (err) {
|
||||
.toFile(outputWebP, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -869,10 +869,10 @@ async.series({
|
||||
}
|
||||
}).add('sharp-file-buffer', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(width, height)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -880,17 +880,17 @@ async.series({
|
||||
}
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
}).on('cycle', (event) => {
|
||||
console.log(`webp ${String(event.target)}`);
|
||||
}).on('complete', function () {
|
||||
callback(null, this.filter('fastest').map('name'));
|
||||
}).run();
|
||||
}
|
||||
}, function (err, results) {
|
||||
}, (err, results) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
Object.keys(results).forEach(function (format) {
|
||||
Object.keys(results).forEach((format) => {
|
||||
if (results[format].toString().substr(0, 5) !== 'sharp') {
|
||||
console.log(`sharp was slower than ${results[format]} for ${format}`);
|
||||
}
|
||||
|
||||
@ -16,13 +16,11 @@ sharp.cache(false);
|
||||
const min = 320;
|
||||
const max = 960;
|
||||
|
||||
const randomDimension = function () {
|
||||
return Math.ceil((Math.random() * (max - min)) + min);
|
||||
};
|
||||
const randomDimension = () => Math.ceil((Math.random() * (max - min)) + min);
|
||||
|
||||
new Benchmark.Suite('random').add('imagemagick', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
imagemagick.resize({
|
||||
srcPath: fixtures.inputJpg,
|
||||
dstPath: fixtures.path('output.jpg'),
|
||||
@ -31,7 +29,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
height: randomDimension(),
|
||||
format: 'jpg',
|
||||
filter: 'Lanczos'
|
||||
}, function (err) {
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -41,12 +39,12 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
}
|
||||
}).add('gm', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
gm(fixtures.inputJpg)
|
||||
.resize(randomDimension(), randomDimension())
|
||||
.filter('Lanczos')
|
||||
.quality(80)
|
||||
.toBuffer(function (err, buffer) {
|
||||
.toBuffer((err, buffer) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -57,10 +55,10 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
}
|
||||
}).add('sharp', {
|
||||
defer: true,
|
||||
fn: function (deferred) {
|
||||
fn: (deferred) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(randomDimension(), randomDimension())
|
||||
.toBuffer(function (err, buffer) {
|
||||
.toBuffer((err, buffer) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -69,7 +67,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
||||
}
|
||||
});
|
||||
}
|
||||
}).on('cycle', function (event) {
|
||||
}).on('cycle', (event) => {
|
||||
console.log(String(event.target));
|
||||
}).on('complete', function () {
|
||||
const winner = this.filter('fastest').map('name');
|
||||
|
||||
14
test/fixtures/index.js
vendored
14
test/fixtures/index.js
vendored
@ -8,9 +8,7 @@ const sharp = require('../../');
|
||||
const maxColourDistance = require('../../lib/sharp')._maxColourDistance;
|
||||
|
||||
// Helpers
|
||||
const getPath = function (filename) {
|
||||
return path.join(__dirname, filename);
|
||||
};
|
||||
const getPath = (filename) => path.join(__dirname, filename);
|
||||
|
||||
// Generates a 64-bit-as-binary-string image fingerprint
|
||||
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
||||
@ -22,7 +20,7 @@ async function fingerprint (image) {
|
||||
.resize(9, 8, { fit: sharp.fit.fill })
|
||||
.raw()
|
||||
.toBuffer()
|
||||
.then(function (data) {
|
||||
.then((data) => {
|
||||
let fingerprint = '';
|
||||
for (let col = 0; col < 8; col++) {
|
||||
for (let row = 0; row < 8; row++) {
|
||||
@ -148,14 +146,12 @@ module.exports = {
|
||||
path: getPath,
|
||||
|
||||
// Path for expected output images
|
||||
expected: function (filename) {
|
||||
return getPath(path.join('expected', filename));
|
||||
},
|
||||
expected: (filename) => getPath(path.join('expected', filename)),
|
||||
|
||||
// Verify similarity of expected vs actual images via fingerprint
|
||||
// Specify distance threshold using `options={threshold: 42}`, default
|
||||
// `threshold` is 5;
|
||||
assertSimilar: async function (expectedImage, actualImage, options, callback) {
|
||||
assertSimilar: async (expectedImage, actualImage, options, callback) => {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
@ -195,7 +191,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
assertMaxColourDistance: function (actualImagePath, expectedImagePath, acceptedDistance) {
|
||||
assertMaxColourDistance: (actualImagePath, expectedImagePath, acceptedDistance) => {
|
||||
if (typeof actualImagePath !== 'string') {
|
||||
throw new TypeError(`\`actualImagePath\` must be a string; got ${actualImagePath}`);
|
||||
}
|
||||
|
||||
@ -8,12 +8,12 @@ const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
|
||||
describe('Alpha transparency', function () {
|
||||
it('Flatten to black', function (_t, done) {
|
||||
describe('Alpha transparency', () => {
|
||||
it('Flatten to black', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten()
|
||||
.resize(400, 300)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@ -21,14 +21,14 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten to RGB orange', function (_t, done) {
|
||||
it('Flatten to RGB orange', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(400, 300)
|
||||
.flatten({
|
||||
background: { r: 255, g: 102, b: 0 }
|
||||
})
|
||||
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@ -36,12 +36,12 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten to CSS/hex orange', function (_t, done) {
|
||||
it('Flatten to CSS/hex orange', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(400, 300)
|
||||
.flatten({ background: '#ff6600' })
|
||||
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(300, info.height);
|
||||
@ -49,13 +49,13 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flatten 16-bit PNG with transparency to orange', function (_t, done) {
|
||||
it('Flatten 16-bit PNG with transparency to orange', (_t, done) => {
|
||||
const output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.flatten({
|
||||
background: { r: 255, g: 102, b: 0 }
|
||||
})
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual(32, info.width);
|
||||
@ -65,10 +65,10 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not flatten', function (_t, done) {
|
||||
it('Do not flatten', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.flatten(false)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -76,10 +76,10 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Ignored for JPEG', function (_t, done) {
|
||||
it('Ignored for JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.flatten({ background: '#ff0000' })
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@ -99,68 +99,60 @@ describe('Alpha transparency', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', () => {
|
||||
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||
const actual = fixtures.path(`output.${base}`);
|
||||
const expected = fixtures.expected(base);
|
||||
return sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.resize(2048, 1536)
|
||||
.toFile(actual)
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
fixtures.assertMaxColourDistance(actual, expected, 102);
|
||||
});
|
||||
});
|
||||
|
||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', () => {
|
||||
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||
const actual = fixtures.path(`output.${base}`);
|
||||
const expected = fixtures.expected(base);
|
||||
return sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||
.resize(1024, 768)
|
||||
.toFile(actual)
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
fixtures.assertMaxColourDistance(actual, expected, 102);
|
||||
});
|
||||
});
|
||||
|
||||
it('Removes alpha from fixtures with transparency, ignores those without', function () {
|
||||
return Promise.all([
|
||||
it('Removes alpha from fixtures with transparency, ignores those without', () => Promise.all([
|
||||
fixtures.inputPngWithTransparency,
|
||||
fixtures.inputPngWithTransparency16bit,
|
||||
fixtures.inputWebPWithTransparency,
|
||||
fixtures.inputJpg,
|
||||
fixtures.inputPng,
|
||||
fixtures.inputWebP
|
||||
].map(function (input) {
|
||||
return sharp(input)
|
||||
].map((input) => sharp(input)
|
||||
.resize(10)
|
||||
.removeAlpha()
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (result) {
|
||||
.then((result) => {
|
||||
assert.strictEqual(3, result.info.channels);
|
||||
});
|
||||
}));
|
||||
});
|
||||
}))));
|
||||
|
||||
it('Ensures alpha from fixtures without transparency, ignores those with', function () {
|
||||
return Promise.all([
|
||||
it('Ensures alpha from fixtures without transparency, ignores those with', () => Promise.all([
|
||||
fixtures.inputPngWithTransparency,
|
||||
fixtures.inputPngWithTransparency16bit,
|
||||
fixtures.inputWebPWithTransparency,
|
||||
fixtures.inputJpg,
|
||||
fixtures.inputPng,
|
||||
fixtures.inputWebP
|
||||
].map(function (input) {
|
||||
return sharp(input)
|
||||
].map((input) => sharp(input)
|
||||
.resize(10)
|
||||
.ensureAlpha()
|
||||
.png()
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (result) {
|
||||
.then((result) => {
|
||||
assert.strictEqual(4, result.info.channels);
|
||||
});
|
||||
}));
|
||||
});
|
||||
}))));
|
||||
|
||||
it('Valid ensureAlpha value used for alpha channel', async () => {
|
||||
const background = { r: 255, g: 0, b: 0 };
|
||||
|
||||
@ -8,18 +8,18 @@ const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
|
||||
describe('Bandbool per-channel boolean operations', function () {
|
||||
describe('Bandbool per-channel boolean operations', () => {
|
||||
[
|
||||
sharp.bool.and,
|
||||
sharp.bool.or,
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function (op) {
|
||||
it(`${op} operation`, function (_t, done) {
|
||||
.forEach((op) => {
|
||||
it(`${op} operation`, (_t, done) => {
|
||||
sharp(fixtures.inputPngBooleanNoAlpha)
|
||||
.bandbool(op)
|
||||
.toColourspace('b-w')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@ -29,24 +29,24 @@ describe('Bandbool per-channel boolean operations', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('sRGB image retains 3 channels', function (_t, done) {
|
||||
it('sRGB image retains 3 channels', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.bandbool('and')
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, info.channels);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid operation', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid operation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().bandbool('fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing operation', function () {
|
||||
assert.throws(function () {
|
||||
it('Missing operation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().bandbool();
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,12 +9,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Blur', function () {
|
||||
it('specific radius 1', function (_t, done) {
|
||||
describe('Blur', () => {
|
||||
it('specific radius 1', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -23,11 +23,11 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 10', function (_t, done) {
|
||||
it('specific radius 10', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(10)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -36,11 +36,11 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific options.sigma 10', function (_t, done) {
|
||||
it('specific options.sigma 10', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur({ sigma: 10 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -49,11 +49,11 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 0.3', function (_t, done) {
|
||||
it('specific radius 0.3', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(0.3)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -62,11 +62,11 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('mild blur', function (_t, done) {
|
||||
it('mild blur', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -75,17 +75,17 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid radius', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid radius', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).blur(0.1);
|
||||
});
|
||||
});
|
||||
|
||||
it('blurred image is smaller than non-blurred', function (_t, done) {
|
||||
it('blurred image is smaller than non-blurred', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(false)
|
||||
.toBuffer(function (err, notBlurred, info) {
|
||||
.toBuffer((err, notBlurred, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, notBlurred.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -94,7 +94,7 @@ describe('Blur', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.blur(true)
|
||||
.toBuffer(function (err, blurred, info) {
|
||||
.toBuffer((err, blurred, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, blurred.length > 0);
|
||||
assert.strictEqual(true, blurred.length < notBlurred.length);
|
||||
@ -106,18 +106,18 @@ describe('Blur', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid precision', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid precision', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).blur({ sigma: 1, precision: 'invalid' });
|
||||
}, /Expected one of: integer, float, approximate for precision but received invalid of type string/);
|
||||
});
|
||||
|
||||
it('invalid minAmplitude', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid minAmplitude', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).blur({ sigma: 1, minAmplitude: 0 });
|
||||
}, /Expected number between 0.001 and 1 for minAmplitude but received 0 of type number/);
|
||||
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).blur({ sigma: 1, minAmplitude: 1.01 });
|
||||
}, /Expected number between 0.001 and 1 for minAmplitude but received 1.01 of type number/);
|
||||
});
|
||||
@ -150,8 +150,8 @@ describe('Blur', function () {
|
||||
await fixtures.assertSimilar(fixtures.expected('blur-10.jpg'), minAmplitudeLow);
|
||||
});
|
||||
|
||||
it('options.sigma is required if options object is passed', function () {
|
||||
assert.throws(function () {
|
||||
it('options.sigma is required if options object is passed', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).blur({ precision: 'invalid' });
|
||||
}, /Expected number between 0.3 and 1000 for options.sigma but received undefined of type undefined/);
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
const sharp = require('../../');
|
||||
|
||||
describe('Boolean operation between two images', function () {
|
||||
describe('Boolean operation between two images', () => {
|
||||
const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest);
|
||||
|
||||
[
|
||||
@ -18,12 +18,12 @@ describe('Boolean operation between two images', function () {
|
||||
sharp.bool.or,
|
||||
sharp.bool.eor
|
||||
]
|
||||
.forEach(function (op) {
|
||||
it(`${op} operation, file`, function (_t, done) {
|
||||
.forEach((op) => {
|
||||
it(`${op} operation, file`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(fixtures.inputJpgBooleanTest, op)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -31,11 +31,11 @@ describe('Boolean operation between two images', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`${op} operation, buffer`, function (_t, done) {
|
||||
it(`${op} operation, buffer`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(inputJpgBooleanTestBuffer, op)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -43,15 +43,15 @@ describe('Boolean operation between two images', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`${op} operation, raw`, function (_t, done) {
|
||||
it(`${op} operation, raw`, (_t, done) => {
|
||||
sharp(fixtures.inputJpgBooleanTest)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.boolean(data, op, { raw: info })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -61,20 +61,20 @@ describe('Boolean operation between two images', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid operation', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid operation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().boolean(fixtures.inputJpgBooleanTest, 'fail');
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid operation, non-string', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid operation, non-string', () => {
|
||||
assert.throws(() => {
|
||||
sharp().boolean(fixtures.inputJpgBooleanTest, null);
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing input', function () {
|
||||
assert.throws(function () {
|
||||
it('Missing input', () => {
|
||||
assert.throws(() => {
|
||||
sharp().boolean();
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,132 +9,132 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../lib');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Clahe', function () {
|
||||
it('width 5 width 5 maxSlope 0', function (_t, done) {
|
||||
describe('Clahe', () => {
|
||||
it('width 5 width 5 maxSlope 0', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 5, height: 5, maxSlope: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-5-5-0.jpg'), data, { threshold: 10 }, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 5 width 5 maxSlope 5', function (_t, done) {
|
||||
it('width 5 width 5 maxSlope 5', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 5, height: 5, maxSlope: 5 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-5-5-5.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 11 width 25 maxSlope 14', function (_t, done) {
|
||||
it('width 11 width 25 maxSlope 14', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 11, height: 25, maxSlope: 14 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-11-25-14.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 50 width 50 maxSlope 0', function (_t, done) {
|
||||
it('width 50 width 50 maxSlope 0', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 50, height: 50, maxSlope: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-50-50-0.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 50 width 50 maxSlope 14', function (_t, done) {
|
||||
it('width 50 width 50 maxSlope 14', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 50, height: 50, maxSlope: 14 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-50-50-14.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 100 width 50 maxSlope 3', function (_t, done) {
|
||||
it('width 100 width 50 maxSlope 3', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 100, height: 50, maxSlope: 3 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-100-50-3.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('width 100 width 100 maxSlope 0', function (_t, done) {
|
||||
it('width 100 width 100 maxSlope 0', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 100, height: 100, maxSlope: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-100-100-0.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid maxSlope', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid maxSlope', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 100, maxSlope: -5 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 100, maxSlope: 110 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 100, maxSlope: 5.5 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 100, maxSlope: 'a string' });
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid width', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid width', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100.5, height: 100 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: -5, height: 100 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: true, height: 100 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 'string test', height: 100 });
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid height', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid height', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 100.5 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: -5 });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: true });
|
||||
});
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe({ width: 100, height: 'string test' });
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid options object', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid options object', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgClahe).clahe(100, 100, 5);
|
||||
});
|
||||
});
|
||||
|
||||
it('uses default maxSlope of 3', function (_t, done) {
|
||||
it('uses default maxSlope of 3', (_t, done) => {
|
||||
sharp(fixtures.inputJpgClahe)
|
||||
.clahe({ width: 100, height: 50 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('clahe-100-50-3.jpg'), data, done);
|
||||
|
||||
@ -10,21 +10,21 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Clone', function () {
|
||||
beforeEach(function () {
|
||||
describe('Clone', () => {
|
||||
beforeEach(() => {
|
||||
sharp.cache(false);
|
||||
});
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
sharp.cache(true);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to multiple Streams', function (_t, done) {
|
||||
it('Read from Stream and write to multiple Streams', (_t, done) => {
|
||||
let finishEventsExpected = 2;
|
||||
// Output stream 1
|
||||
const output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||
const writable1 = fs.createWriteStream(output1);
|
||||
writable1.on('finish', function () {
|
||||
sharp(output1).toBuffer(function (err, data, info) {
|
||||
writable1.on('finish', () => {
|
||||
sharp(output1).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -41,8 +41,8 @@ describe('Clone', function () {
|
||||
// Output stream 2
|
||||
const output2 = fixtures.path('output.multi-stream.2.jpg');
|
||||
const writable2 = fs.createWriteStream(output2);
|
||||
writable2.on('finish', function () {
|
||||
sharp(output2).toBuffer(function (err, data, info) {
|
||||
writable2.on('finish', () => {
|
||||
sharp(output2).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -65,14 +65,14 @@ describe('Clone', function () {
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||
});
|
||||
|
||||
it('Stream-based input attaches finish event listener to original', function () {
|
||||
it('Stream-based input attaches finish event listener to original', () => {
|
||||
const original = sharp();
|
||||
const clone = original.clone();
|
||||
assert.strictEqual(1, original.listenerCount('finish'));
|
||||
assert.strictEqual(0, clone.listenerCount('finish'));
|
||||
});
|
||||
|
||||
it('Non Stream-based input does not attach finish event listeners', function () {
|
||||
it('Non Stream-based input does not attach finish event listeners', () => {
|
||||
const original = sharp(fixtures.inputJpg);
|
||||
const clone = original.clone();
|
||||
assert.strictEqual(0, original.listenerCount('finish'));
|
||||
|
||||
@ -9,15 +9,15 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Colour space conversion', function () {
|
||||
it('To greyscale', function (_t, done) {
|
||||
describe('Colour space conversion', () => {
|
||||
it('To greyscale', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale()
|
||||
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
||||
});
|
||||
|
||||
it('To greyscale with gamma correction', function (_t, done) {
|
||||
it('To greyscale with gamma correction', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.gamma()
|
||||
@ -25,19 +25,19 @@ describe('Colour space conversion', function () {
|
||||
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
||||
});
|
||||
|
||||
it('Not to greyscale', function (_t, done) {
|
||||
it('Not to greyscale', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale(false)
|
||||
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
||||
});
|
||||
|
||||
it('Greyscale with single channel output', function (_t, done) {
|
||||
it('Greyscale with single channel output', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.greyscale()
|
||||
.toColourspace('b-w')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, info.channels);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -56,10 +56,10 @@ describe('Colour space conversion', function () {
|
||||
assert.strictEqual(format, 'webp');
|
||||
});
|
||||
|
||||
it('From CMYK to sRGB', function (_t, done) {
|
||||
it('From CMYK to sRGB', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(320)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -68,13 +68,13 @@ describe('Colour space conversion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('From CMYK to sRGB with white background, not yellow', function (_t, done) {
|
||||
it('From CMYK to sRGB with white background, not yellow', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(320, 240, {
|
||||
fit: sharp.fit.contain,
|
||||
background: 'white'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -83,10 +83,10 @@ describe('Colour space conversion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('From profile-less CMYK to sRGB', function (_t, done) {
|
||||
it('From profile-less CMYK to sRGB', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCmykNoProfile)
|
||||
.resize(320)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -130,7 +130,7 @@ describe('Colour space conversion', function () {
|
||||
.pipelineColourspace('cmyk')
|
||||
.withIccProfile(fixtures.path('XCMYK 2017.icc'))
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -144,13 +144,13 @@ describe('Colour space conversion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (_t, done) {
|
||||
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', (_t, done) => {
|
||||
sharp(fixtures.inputPngGradients)
|
||||
.pipelineColourspace('rgb16')
|
||||
.resize(320)
|
||||
.gamma()
|
||||
.toColourspace('srgb')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
fixtures.assertSimilar(fixtures.expected('colourspace-gradients-gamma-resize.png'), data, {
|
||||
@ -178,15 +178,15 @@ describe('Colour space conversion', function () {
|
||||
assert.strictEqual(b, 34);
|
||||
});
|
||||
|
||||
it('Invalid pipelineColourspace input', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid pipelineColourspace input', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.pipelineColorspace(null);
|
||||
}, /Expected string for colourspace but received null of type object/);
|
||||
});
|
||||
|
||||
it('Invalid toColourspace input', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid toColourspace input', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toColourspace(null);
|
||||
});
|
||||
|
||||
@ -9,8 +9,8 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Convolve', function () {
|
||||
it('specific convolution kernel 1', function (_t, done) {
|
||||
describe('Convolve', () => {
|
||||
it('specific convolution kernel 1', (_t, done) => {
|
||||
sharp(fixtures.inputPngStripesV)
|
||||
.convolve({
|
||||
width: 3,
|
||||
@ -23,7 +23,7 @@ describe('Convolve', function () {
|
||||
10, 20, 10
|
||||
]
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -32,7 +32,7 @@ describe('Convolve', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific convolution kernel 2', function (_t, done) {
|
||||
it('specific convolution kernel 2', (_t, done) => {
|
||||
sharp(fixtures.inputPngStripesH)
|
||||
.convolve({
|
||||
width: 3,
|
||||
@ -43,7 +43,7 @@ describe('Convolve', function () {
|
||||
1, 0, 1
|
||||
]
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -52,7 +52,7 @@ describe('Convolve', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('horizontal Sobel operator', function (_t, done) {
|
||||
it('horizontal Sobel operator', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.convolve({
|
||||
@ -64,7 +64,7 @@ describe('Convolve', function () {
|
||||
-1, 0, 1
|
||||
]
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -73,14 +73,14 @@ describe('Convolve', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid kernel specification', function () {
|
||||
it('missing', function () {
|
||||
assert.throws(function () {
|
||||
describe('invalid kernel specification', () => {
|
||||
it('missing', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).convolve({});
|
||||
});
|
||||
});
|
||||
it('incorrect data format', function () {
|
||||
assert.throws(function () {
|
||||
it('incorrect data format', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).convolve({
|
||||
width: 3,
|
||||
height: 3,
|
||||
@ -88,8 +88,8 @@ describe('Convolve', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('incorrect dimensions', function () {
|
||||
assert.throws(function () {
|
||||
it('incorrect dimensions', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).convolve({
|
||||
width: 3,
|
||||
height: 4,
|
||||
|
||||
@ -4,11 +4,11 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Dilate', function () {
|
||||
it('dilate 1 png', function (_t, done) {
|
||||
describe('Dilate', () => {
|
||||
it('dilate 1 png', (_t, done) => {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.dilate(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
@ -17,10 +17,10 @@ describe('Dilate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('dilate 1 png - default width', function (_t, done) {
|
||||
it('dilate 1 png - default width', (_t, done) => {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.dilate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
@ -29,8 +29,8 @@ describe('Dilate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid dilation width', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid dilation width', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).dilate(-1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,11 +4,11 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Erode', function () {
|
||||
it('erode 1 png', function (_t, done) {
|
||||
describe('Erode', () => {
|
||||
it('erode 1 png', (_t, done) => {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.erode(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
@ -17,10 +17,10 @@ describe('Erode', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('erode 1 png - default width', function (_t, done) {
|
||||
it('erode 1 png - default width', (_t, done) => {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.erode()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
@ -29,8 +29,8 @@ describe('Erode', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid erosion width', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid erosion width', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).erode(-1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,13 +9,13 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Extend', function () {
|
||||
describe('extend all sides equally via a single value', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
describe('Extend', () => {
|
||||
describe('extend all sides equally via a single value', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(120)
|
||||
.extend(10)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(140, info.width);
|
||||
assert.strictEqual(118, info.height);
|
||||
@ -23,11 +23,11 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Animated WebP', function (_t, done) {
|
||||
it('Animated WebP', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(120)
|
||||
.extend(10)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(140, info.width);
|
||||
assert.strictEqual(140 * 9, info.height);
|
||||
@ -37,7 +37,7 @@ describe('Extend', function () {
|
||||
});
|
||||
|
||||
['background', 'copy', 'mirror', 'repeat'].forEach(extendWith => {
|
||||
it(`extends all sides with animated WebP (${extendWith})`, function (_t, done) {
|
||||
it(`extends all sides with animated WebP (${extendWith})`, (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(120)
|
||||
.extend({
|
||||
@ -47,7 +47,7 @@ describe('Extend', function () {
|
||||
left: 40,
|
||||
right: 40
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(200 * 9, info.height);
|
||||
@ -55,7 +55,7 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`extend all sides equally with RGB (${extendWith})`, function (_t, done) {
|
||||
it(`extend all sides equally with RGB (${extendWith})`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(120)
|
||||
.extend({
|
||||
@ -66,7 +66,7 @@ describe('Extend', function () {
|
||||
right: 10,
|
||||
background: { r: 255, g: 0, b: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(140, info.width);
|
||||
assert.strictEqual(118, info.height);
|
||||
@ -74,7 +74,7 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`extend sides unequally with RGBA (${extendWith})`, function (_t, done) {
|
||||
it(`extend sides unequally with RGBA (${extendWith})`, (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(120)
|
||||
.extend({
|
||||
@ -84,7 +84,7 @@ describe('Extend', function () {
|
||||
right: 35,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(165, info.width);
|
||||
assert.strictEqual(170, info.height);
|
||||
@ -92,7 +92,7 @@ describe('Extend', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`PNG with 2 channels (${extendWith})`, function (_t, done) {
|
||||
it(`PNG with 2 channels (${extendWith})`, (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extend({
|
||||
extendWith,
|
||||
@ -102,7 +102,7 @@ describe('Extend', function () {
|
||||
right: 80,
|
||||
background: 'transparent'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -147,13 +147,13 @@ describe('Extend', function () {
|
||||
assert.strictEqual(1470, height);
|
||||
});
|
||||
|
||||
it('missing parameter fails', function () {
|
||||
assert.throws(function () {
|
||||
it('missing parameter fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp().extend();
|
||||
});
|
||||
});
|
||||
it('negative fails', function () {
|
||||
assert.throws(function () {
|
||||
it('negative fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp().extend(-1);
|
||||
});
|
||||
});
|
||||
@ -191,7 +191,7 @@ describe('Extend', function () {
|
||||
assert.doesNotThrow(() => sharp().extend({ top: 1, left: 2, bottom: 3 }));
|
||||
});
|
||||
|
||||
it('should add alpha channel before extending with a transparent Background', function (_t, done) {
|
||||
it('should add alpha channel before extending with a transparent Background', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
.extend({
|
||||
bottom: 10,
|
||||
@ -199,7 +199,7 @@ describe('Extend', function () {
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.toFormat(sharp.format.png)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(610, info.width);
|
||||
assert.strictEqual(460, info.height);
|
||||
|
||||
@ -9,11 +9,11 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Partial image extraction', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
describe('Partial image extraction', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(20, info.width);
|
||||
assert.strictEqual(20, info.height);
|
||||
@ -21,10 +21,10 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function (_t, done) {
|
||||
it('PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(400, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@ -32,10 +32,10 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function (_t, done) {
|
||||
it('WebP', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(125, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
@ -43,12 +43,12 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Animated WebP', function () {
|
||||
it('Before resize', function (_t, done) {
|
||||
describe('Animated WebP', () => {
|
||||
it('Before resize', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.extract({ left: 0, top: 30, width: 80, height: 20 })
|
||||
.resize(320, 80)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(80 * 9, info.height);
|
||||
@ -56,11 +56,11 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('After resize', function (_t, done) {
|
||||
it('After resize', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(320, 320)
|
||||
.extract({ left: 0, top: 120, width: 320, height: 80 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(80 * 9, info.height);
|
||||
@ -69,10 +69,10 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF', function (_t, done) {
|
||||
it('TIFF', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(341, info.width);
|
||||
assert.strictEqual(529, info.height);
|
||||
@ -80,11 +80,11 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Before resize', function (_t, done) {
|
||||
it('Before resize', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
||||
.resize(100, 100)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@ -92,13 +92,13 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('After resize and crop', function (_t, done) {
|
||||
it('After resize and crop', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(500, 500, {
|
||||
position: sharp.gravity.north
|
||||
})
|
||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@ -106,14 +106,14 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Before and after resize and crop', function (_t, done) {
|
||||
it('Before and after resize and crop', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
||||
.resize(500, 500, {
|
||||
position: sharp.gravity.north
|
||||
})
|
||||
.extract({ left: 10, top: 10, width: 100, height: 100 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@ -121,12 +121,12 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Extract then rotate', function (_t, done) {
|
||||
it('Extract then rotate', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||
.rotate(90)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(280, info.width);
|
||||
assert.strictEqual(380, info.height);
|
||||
@ -134,11 +134,11 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate then extract', function (_t, done) {
|
||||
it('Rotate then extract', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.rotate(90)
|
||||
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(280, info.width);
|
||||
assert.strictEqual(380, info.height);
|
||||
@ -146,12 +146,12 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Extract then rotate then extract', function (_t, done) {
|
||||
it('Extract then rotate then extract', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extract({ left: 20, top: 10, width: 180, height: 280 })
|
||||
.rotate(90)
|
||||
.extract({ left: 20, top: 10, width: 200, height: 100 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@ -159,12 +159,12 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Extract then rotate non-90 anagle', function (_t, done) {
|
||||
it('Extract then rotate non-90 anagle', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||
.rotate(45)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(467, info.width);
|
||||
assert.strictEqual(467, info.height);
|
||||
@ -172,12 +172,12 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate then extract non-90 angle', function (_t, done) {
|
||||
it('Rotate then extract non-90 angle', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.rotate(45)
|
||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(380, info.width);
|
||||
assert.strictEqual(280, info.height);
|
||||
@ -220,11 +220,11 @@ describe('Partial image extraction', function () {
|
||||
image: fixtures.inputJpgWithLandscapeExif8
|
||||
}
|
||||
].forEach(({ name, image }) => {
|
||||
it(name, function (_t, done) {
|
||||
it(name, (_t, done) => {
|
||||
sharp(image)
|
||||
.rotate()
|
||||
.extract({ left: 0, top: 208, width: 60, height: 40 })
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('rotate-mirror-extract.jpg'), data, done);
|
||||
});
|
||||
@ -232,67 +232,67 @@ describe('Partial image extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid parameters', function () {
|
||||
describe('using the legacy extract(top,left,width,height) syntax', function () {
|
||||
it('String top', function () {
|
||||
assert.throws(function () {
|
||||
describe('Invalid parameters', () => {
|
||||
describe('using the legacy extract(top,left,width,height) syntax', () => {
|
||||
it('String top', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-integral left', function () {
|
||||
assert.throws(function () {
|
||||
it('Non-integral left', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Negative width - negative', function () {
|
||||
assert.throws(function () {
|
||||
it('Negative width - negative', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract(10, 10, -10, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('Null height', function () {
|
||||
assert.throws(function () {
|
||||
it('Null height', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract(10, 10, 10, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Undefined', function () {
|
||||
assert.throws(function () {
|
||||
it('Undefined', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract();
|
||||
});
|
||||
});
|
||||
|
||||
it('String top', function () {
|
||||
assert.throws(function () {
|
||||
it('String top', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 'spoons', width: 10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-integral left', function () {
|
||||
assert.throws(function () {
|
||||
it('Non-integral left', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10.2, top: 10, width: 10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Negative width - negative', function () {
|
||||
assert.throws(function () {
|
||||
it('Negative width - negative', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: -10, height: 10 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Null height', function () {
|
||||
assert.throws(function () {
|
||||
it('Null height', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: 10, height: null });
|
||||
});
|
||||
});
|
||||
|
||||
it('Bad image area', function (_t, done) {
|
||||
it('Bad image area', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual(err.message, 'extract_area: bad extract area');
|
||||
done();
|
||||
@ -302,7 +302,7 @@ describe('Partial image extraction', function () {
|
||||
it('Multiple extract emits warning', () => {
|
||||
let warningMessage = '';
|
||||
const s = sharp();
|
||||
s.on('warning', function (msg) { warningMessage = msg; });
|
||||
s.on('warning', (msg) => { warningMessage = msg; });
|
||||
const options = { top: 0, left: 0, width: 1, height: 1 };
|
||||
s.extract(options).extract(options);
|
||||
assert.strictEqual(warningMessage, '');
|
||||
@ -313,7 +313,7 @@ describe('Partial image extraction', function () {
|
||||
it('Multiple rotate+extract emits warning', () => {
|
||||
let warningMessage = '';
|
||||
const s = sharp().rotate();
|
||||
s.on('warning', function (msg) { warningMessage = msg; });
|
||||
s.on('warning', (msg) => { warningMessage = msg; });
|
||||
const options = { top: 0, left: 0, width: 1, height: 1 };
|
||||
s.extract(options).extract(options);
|
||||
assert.strictEqual(warningMessage, '');
|
||||
@ -324,7 +324,7 @@ describe('Partial image extraction', function () {
|
||||
it('Multiple extract+resize emits warning', () => {
|
||||
let warningMessage = '';
|
||||
const s = sharp();
|
||||
s.on('warning', function (msg) { warningMessage = msg; });
|
||||
s.on('warning', (msg) => { warningMessage = msg; });
|
||||
const options = { top: 0, left: 0, width: 1, height: 1 };
|
||||
s.extract(options).extract(options);
|
||||
assert.strictEqual(warningMessage, '');
|
||||
|
||||
@ -9,12 +9,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Image channel extraction', function () {
|
||||
it('Red channel', function (_t, done) {
|
||||
describe('Image channel extraction', () => {
|
||||
it('Red channel', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('red')
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -22,11 +22,11 @@ describe('Image channel extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Green channel', function (_t, done) {
|
||||
it('Green channel', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('green')
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -34,11 +34,11 @@ describe('Image channel extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel', function (_t, done) {
|
||||
it('Blue channel', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel('blue')
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -46,11 +46,11 @@ describe('Image channel extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Blue channel by number', function (_t, done) {
|
||||
it('Blue channel by number', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(2)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -67,23 +67,23 @@ describe('Image channel extraction', function () {
|
||||
assert.strictEqual(chroma, 104);
|
||||
});
|
||||
|
||||
it('Alpha from 16-bit PNG', function (_t, done) {
|
||||
it('Alpha from 16-bit PNG', (_t, done) => {
|
||||
const output = fixtures.path('output.extract-alpha-16bit.png');
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(16)
|
||||
.extractChannel(3)
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-alpha-16bit.png'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Alpha from 2-channel input', function (_t, done) {
|
||||
it('Alpha from 2-channel input', (_t, done) => {
|
||||
const output = fixtures.path('output.extract-alpha-2-channel.png');
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extractChannel('alpha')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, info.channels);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-alpha-2-channel.png'));
|
||||
@ -91,15 +91,15 @@ describe('Image channel extraction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid channel number', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid channel number', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('No arguments', function () {
|
||||
assert.throws(function () {
|
||||
it('No arguments', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.extractChannel();
|
||||
});
|
||||
|
||||
@ -11,10 +11,10 @@ const sharp = require('../../lib');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('failOn', () => {
|
||||
it('handles truncated JPEG', function (_t, done) {
|
||||
it('handles truncated JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpgTruncated, { failOn: 'none' })
|
||||
.resize(32, 24)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(32, info.width);
|
||||
@ -23,17 +23,17 @@ describe('failOn', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('handles truncated PNG, emits warnings', function (_t, done) {
|
||||
it('handles truncated PNG, emits warnings', (_t, done) => {
|
||||
let isWarningEmitted = false;
|
||||
sharp(fixtures.inputPngTruncated, { failOn: 'none' })
|
||||
.on('warning', function (warning) {
|
||||
.on('warning', (warning) => {
|
||||
assert.ok(
|
||||
['read gave 2 warnings', 'not enough data', 'end of stream']
|
||||
.some(m => warning.includes(m)));
|
||||
isWarningEmitted = true;
|
||||
})
|
||||
.resize(32, 24)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, isWarningEmitted);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -71,8 +71,8 @@ describe('failOn', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('returns errors to callback for truncated JPEG', function (_t, done) {
|
||||
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
||||
it('returns errors to callback for truncated JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer((err, data, info) => {
|
||||
assert.ok(err.message.includes('VipsJpeg: premature end of'), err);
|
||||
assert.strictEqual(data, undefined);
|
||||
assert.strictEqual(info, undefined);
|
||||
@ -80,8 +80,8 @@ describe('failOn', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns errors to callback for truncated PNG', function (_t, done) {
|
||||
sharp(fixtures.inputPngTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
||||
it('returns errors to callback for truncated PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPngTruncated, { failOn: 'truncated' }).toBuffer((err, data, info) => {
|
||||
assert.ok(err.message.includes('read error'), err);
|
||||
assert.strictEqual(data, undefined);
|
||||
assert.strictEqual(info, undefined);
|
||||
@ -89,7 +89,7 @@ describe('failOn', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects promises for truncated JPEG', function (_t, done) {
|
||||
it('rejects promises for truncated JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpgTruncated, { failOn: 'error' })
|
||||
.toBuffer()
|
||||
.then(() => {
|
||||
|
||||
@ -7,23 +7,23 @@ const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Test fixtures', function () {
|
||||
describe('assertMaxColourDistance', function () {
|
||||
it('should throw an Error when images have a different number of channels', function () {
|
||||
assert.throws(function () {
|
||||
describe('Test fixtures', () => {
|
||||
describe('assertMaxColourDistance', () => {
|
||||
it('should throw an Error when images have a different number of channels', () => {
|
||||
assert.throws(() => {
|
||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer1, fixtures.inputJpg);
|
||||
});
|
||||
});
|
||||
it('should throw an Error when images have different dimensions', function () {
|
||||
assert.throws(function () {
|
||||
it('should throw an Error when images have different dimensions', () => {
|
||||
assert.throws(() => {
|
||||
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', () => {
|
||||
const image = fixtures.inputPngOverlayLayer0;
|
||||
fixtures.assertMaxColourDistance(image, image, 0);
|
||||
});
|
||||
it('should accept a numeric threshold for two different images', function () {
|
||||
it('should accept a numeric threshold for two different images', () => {
|
||||
fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer0, fixtures.inputPngOverlayLayer1, 100);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,11 +9,11 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Gamma correction', function () {
|
||||
it('value of 0.0 (disabled)', function (_t, done) {
|
||||
describe('Gamma correction', () => {
|
||||
it('value of 0.0 (disabled)', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
@ -22,11 +22,11 @@ describe('Gamma correction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('value of 2.2 (default)', function (_t, done) {
|
||||
it('value of 2.2 (default)', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.gamma()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
@ -35,11 +35,11 @@ describe('Gamma correction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('value of 3.0', function (_t, done) {
|
||||
it('value of 3.0', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.gamma(3)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
@ -48,11 +48,11 @@ describe('Gamma correction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('input value of 2.2, output value of 3.0', function (_t, done) {
|
||||
it('input value of 2.2, output value of 3.0', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||
.resize(129, 111)
|
||||
.gamma(2.2, 3.0)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(129, info.width);
|
||||
@ -61,12 +61,12 @@ describe('Gamma correction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('alpha transparency', function (_t, done) {
|
||||
it('alpha transparency', (_t, done) => {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(320)
|
||||
.gamma()
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -74,14 +74,14 @@ describe('Gamma correction', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid first parameter value', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid first parameter value', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid second parameter value', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid second parameter value', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpgWithGammaHoliness).gamma(2.2, 4);
|
||||
});
|
||||
});
|
||||
|
||||
@ -199,11 +199,11 @@ describe('GIF input', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should work with streams when only animated is set', function (_t, done) {
|
||||
it('should work with streams when only animated is set', (_t, done) => {
|
||||
fs.createReadStream(fixtures.inputGifAnimated)
|
||||
.pipe(sharp({ animated: true }))
|
||||
.gif()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('gif', info.format);
|
||||
@ -211,11 +211,11 @@ describe('GIF input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with streams when only pages is set', function (_t, done) {
|
||||
it('should work with streams when only pages is set', (_t, done) => {
|
||||
fs.createReadStream(fixtures.inputGifAnimated)
|
||||
.pipe(sharp({ pages: -1 }))
|
||||
.gif()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('gif', info.format);
|
||||
|
||||
324
test/unit/io.js
324
test/unit/io.js
@ -13,18 +13,18 @@ const fixtures = require('../fixtures');
|
||||
|
||||
const outputJpg = fixtures.path('output.jpg');
|
||||
|
||||
describe('Input/output', function () {
|
||||
beforeEach(function () {
|
||||
describe('Input/output', () => {
|
||||
beforeEach(() => {
|
||||
sharp.cache(false);
|
||||
});
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
sharp.cache(true);
|
||||
});
|
||||
|
||||
it('Read from File and write to Stream', function (_t, done) {
|
||||
it('Read from File and write to Stream', (_t, done) => {
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
writable.on('close', function () {
|
||||
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||
writable.on('close', () => {
|
||||
sharp(outputJpg).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -37,11 +37,11 @@ describe('Input/output', function () {
|
||||
sharp(fixtures.inputJpg).resize(320, 240).pipe(writable);
|
||||
});
|
||||
|
||||
it('Read from Buffer and write to Stream', function (_t, done) {
|
||||
it('Read from Buffer and write to Stream', (_t, done) => {
|
||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
writable.on('close', function () {
|
||||
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||
writable.on('close', () => {
|
||||
sharp(outputJpg).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -54,9 +54,9 @@ describe('Input/output', function () {
|
||||
sharp(inputJpgBuffer).resize(320, 240).pipe(writable);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to File', function (_t, done) {
|
||||
it('Read from Stream and write to File', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().resize(320, 240).toFile(outputJpg, function (err, info) {
|
||||
const pipeline = sharp().resize(320, 240).toFile(outputJpg, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -67,9 +67,9 @@ describe('Input/output', function () {
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Buffer', function (_t, done) {
|
||||
it('Read from Stream and write to Buffer', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) {
|
||||
const pipeline = sharp().resize(320, 240).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -81,23 +81,23 @@ describe('Input/output', function () {
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Buffer via Promise resolved with Buffer', function () {
|
||||
it('Read from Stream and write to Buffer via Promise resolved with Buffer', () => {
|
||||
const pipeline = sharp().resize(1, 1);
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(pipeline);
|
||||
return pipeline
|
||||
.toBuffer({ resolveWithObject: false })
|
||||
.then(function (data) {
|
||||
.then((data) => {
|
||||
assert.strictEqual(true, data instanceof Buffer);
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('Read from Stream and write to Buffer via Promise resolved with Object', function () {
|
||||
it('Read from Stream and write to Buffer via Promise resolved with Object', () => {
|
||||
const pipeline = sharp().resize(1, 1);
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(pipeline);
|
||||
return pipeline
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (object) {
|
||||
.then((object) => {
|
||||
assert.strictEqual('object', typeof object);
|
||||
assert.strictEqual('object', typeof object.info);
|
||||
assert.strictEqual('jpeg', object.info.format);
|
||||
@ -109,21 +109,18 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Read from File and write to Buffer via Promise resolved with Buffer', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Read from File and write to Buffer via Promise resolved with Buffer', () => sharp(fixtures.inputJpg)
|
||||
.resize(1, 1)
|
||||
.toBuffer({ resolveWithObject: false })
|
||||
.then(function (data) {
|
||||
.then((data) => {
|
||||
assert.strictEqual(true, data instanceof Buffer);
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Read from File and write to Buffer via Promise resolved with Object', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Read from File and write to Buffer via Promise resolved with Object', () => sharp(fixtures.inputJpg)
|
||||
.resize(1, 1)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (object) {
|
||||
.then((object) => {
|
||||
assert.strictEqual('object', typeof object);
|
||||
assert.strictEqual('object', typeof object.info);
|
||||
assert.strictEqual('jpeg', object.info.format);
|
||||
@ -132,14 +129,13 @@ describe('Input/output', function () {
|
||||
assert.strictEqual(3, object.info.channels);
|
||||
assert.strictEqual(true, object.data instanceof Buffer);
|
||||
assert.strictEqual(true, object.data.length > 0);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Read from Stream and write to Stream', function (_t, done) {
|
||||
it('Read from Stream and write to Stream', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
writable.on('close', function () {
|
||||
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||
writable.on('close', () => {
|
||||
sharp(outputJpg).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -220,46 +216,46 @@ describe('Input/output', function () {
|
||||
assert.strictEqual(info.height, 1);
|
||||
});
|
||||
|
||||
it('Stream should emit info event', function (_t, done) {
|
||||
it('Stream should emit info event', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
let infoEventEmitted = false;
|
||||
pipeline.on('info', function (info) {
|
||||
pipeline.on('info', (info) => {
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
infoEventEmitted = true;
|
||||
});
|
||||
writable.on('close', function () {
|
||||
writable.on('close', () => {
|
||||
assert.strictEqual(true, infoEventEmitted);
|
||||
fs.rm(outputJpg, done);
|
||||
});
|
||||
readable.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Stream should emit close event', function (_t, done) {
|
||||
it('Stream should emit close event', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
let closeEventEmitted = false;
|
||||
pipeline.on('close', function () {
|
||||
pipeline.on('close', () => {
|
||||
closeEventEmitted = true;
|
||||
});
|
||||
writable.on('close', function () {
|
||||
writable.on('close', () => {
|
||||
assert.strictEqual(true, closeEventEmitted);
|
||||
fs.rm(outputJpg, done);
|
||||
});
|
||||
readable.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Handle Stream to Stream error ', function (_t, done) {
|
||||
it('Handle Stream to Stream error ', (_t, done) => {
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
let anErrorWasEmitted = false;
|
||||
pipeline.on('error', function (err) {
|
||||
pipeline.on('error', (err) => {
|
||||
anErrorWasEmitted = !!err;
|
||||
}).on('end', function () {
|
||||
}).on('end', () => {
|
||||
assert(anErrorWasEmitted);
|
||||
fs.rm(outputJpg, done);
|
||||
});
|
||||
@ -268,12 +264,12 @@ describe('Input/output', function () {
|
||||
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
||||
});
|
||||
|
||||
it('Handle File to Stream error', function (_t, done) {
|
||||
it('Handle File to Stream error', (_t, done) => {
|
||||
const readableButNotAnImage = sharp(__filename).resize(320, 240);
|
||||
let anErrorWasEmitted = false;
|
||||
readableButNotAnImage.on('error', function (err) {
|
||||
readableButNotAnImage.on('error', (err) => {
|
||||
anErrorWasEmitted = !!err;
|
||||
}).on('end', function () {
|
||||
}).on('end', () => {
|
||||
assert(anErrorWasEmitted);
|
||||
fs.rm(outputJpg, done);
|
||||
});
|
||||
@ -281,11 +277,11 @@ describe('Input/output', function () {
|
||||
readableButNotAnImage.pipe(writable);
|
||||
});
|
||||
|
||||
it('Readable side of Stream can start flowing after Writable side has finished', function (_t, done) {
|
||||
it('Readable side of Stream can start flowing after Writable side has finished', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const writable = fs.createWriteStream(outputJpg);
|
||||
writable.on('close', function () {
|
||||
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||
writable.on('close', () => {
|
||||
sharp(outputJpg).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -297,7 +293,7 @@ describe('Input/output', function () {
|
||||
});
|
||||
const pipeline = sharp().resize(320, 240);
|
||||
readable.pipe(pipeline);
|
||||
pipeline.on('finish', function () {
|
||||
pipeline.on('finish', () => {
|
||||
pipeline.pipe(writable);
|
||||
});
|
||||
});
|
||||
@ -350,11 +346,11 @@ describe('Input/output', function () {
|
||||
})
|
||||
);
|
||||
|
||||
it('Support output to jpg format', function (_t, done) {
|
||||
it('Support output to jpg format', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.toFormat('jpg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -365,11 +361,11 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Support output to tif format', function (_t, done) {
|
||||
it('Support output to tif format', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 240)
|
||||
.toFormat('tif')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -394,76 +390,76 @@ describe('Input/output', function () {
|
||||
assert.strictEqual(Buffer.isBuffer(data), true);
|
||||
});
|
||||
|
||||
it('Fail when output File is input File', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function (err) {
|
||||
it('Fail when output File is input File', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, (err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is input File via Promise', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function () {
|
||||
it('Fail when output File is input File via Promise', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(() => {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is input File (relative output, absolute input)', function (_t, done) {
|
||||
it('Fail when output File is input File (relative output, absolute input)', (_t, done) => {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(fixtures.inputJpg).toFile(relativePath, function (err) {
|
||||
sharp(fixtures.inputJpg).toFile(relativePath, (err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is input File via Promise (relative output, absolute input)', function (_t, done) {
|
||||
it('Fail when output File is input File via Promise (relative output, absolute input)', (_t, done) => {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(fixtures.inputJpg).toFile(relativePath).then(function () {
|
||||
sharp(fixtures.inputJpg).toFile(relativePath).then(() => {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is input File (relative input, absolute output)', function (_t, done) {
|
||||
it('Fail when output File is input File (relative input, absolute output)', (_t, done) => {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(relativePath).toFile(fixtures.inputJpg, function (err) {
|
||||
sharp(relativePath).toFile(fixtures.inputJpg, (err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is input File via Promise (relative input, absolute output)', function (_t, done) {
|
||||
it('Fail when output File is input File via Promise (relative input, absolute output)', (_t, done) => {
|
||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||
sharp(relativePath).toFile(fixtures.inputJpg).then(function () {
|
||||
sharp(relativePath).toFile(fixtures.inputJpg).then(() => {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is empty', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).toFile('', function (err) {
|
||||
it('Fail when output File is empty', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).toFile('', (err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Missing output file path', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Fail when output File is empty via Promise', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).toFile('').then(function () {
|
||||
it('Fail when output File is empty via Promise', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).toFile('').then(() => {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual('Missing output file path', err.message);
|
||||
done();
|
||||
@ -494,41 +490,39 @@ describe('Input/output', function () {
|
||||
)
|
||||
);
|
||||
|
||||
describe('Fail for unsupported input', function () {
|
||||
it('Undefined', function () {
|
||||
assert.throws(function () {
|
||||
describe('Fail for unsupported input', () => {
|
||||
it('Undefined', () => {
|
||||
assert.throws(() => {
|
||||
sharp(undefined);
|
||||
});
|
||||
});
|
||||
it('Null', function () {
|
||||
assert.throws(function () {
|
||||
it('Null', () => {
|
||||
assert.throws(() => {
|
||||
sharp(null);
|
||||
});
|
||||
});
|
||||
it('Numeric', function () {
|
||||
assert.throws(function () {
|
||||
it('Numeric', () => {
|
||||
assert.throws(() => {
|
||||
sharp(1);
|
||||
});
|
||||
});
|
||||
it('Boolean', function () {
|
||||
assert.throws(function () {
|
||||
it('Boolean', () => {
|
||||
assert.throws(() => {
|
||||
sharp(true);
|
||||
});
|
||||
});
|
||||
it('Error Object', function () {
|
||||
assert.throws(function () {
|
||||
it('Error Object', () => {
|
||||
assert.throws(() => {
|
||||
sharp(new Error());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Promises/A+', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Promises/A+', () => sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.toBuffer();
|
||||
});
|
||||
.toBuffer());
|
||||
|
||||
it('Invalid output format', function (_t, done) {
|
||||
it('Invalid output format', (_t, done) => {
|
||||
let isValid = false;
|
||||
try {
|
||||
sharp().toFormat('zoinks');
|
||||
@ -538,30 +532,30 @@ describe('Input/output', function () {
|
||||
done();
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('File input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('Buffer input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Stream input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('Stream input with corrupt header fails gracefully', (_t, done) => {
|
||||
const transformer = sharp();
|
||||
transformer
|
||||
.toBuffer()
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
done(new Error('Unexpectedly resolved Promise'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
.catch((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
@ -570,13 +564,13 @@ describe('Input/output', function () {
|
||||
.pipe(transformer);
|
||||
});
|
||||
|
||||
describe('Output filename with unknown extension', function () {
|
||||
describe('Output filename with unknown extension', () => {
|
||||
const outputZoinks = fixtures.path('output.zoinks');
|
||||
|
||||
it('Match JPEG input', function (_t, done) {
|
||||
it('Match JPEG input', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 80)
|
||||
.toFile(outputZoinks, function (err, info) {
|
||||
.toFile(outputZoinks, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -586,10 +580,10 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Match PNG input', function (_t, done) {
|
||||
it('Match PNG input', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 80)
|
||||
.toFile(outputZoinks, function (err, info) {
|
||||
.toFile(outputZoinks, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -599,10 +593,10 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Match WebP input', function (_t, done) {
|
||||
it('Match WebP input', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 80)
|
||||
.toFile(outputZoinks, function (err, info) {
|
||||
.toFile(outputZoinks, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -612,10 +606,10 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Match TIFF input', function (_t, done) {
|
||||
it('Match TIFF input', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 80)
|
||||
.toFile(outputZoinks, function (err, info) {
|
||||
.toFile(outputZoinks, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('tiff', info.format);
|
||||
@ -625,11 +619,11 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Force JPEG format for PNG input', function (_t, done) {
|
||||
it('Force JPEG format for PNG input', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 80)
|
||||
.jpeg()
|
||||
.toFile(outputZoinks, function (err, info) {
|
||||
.toFile(outputZoinks, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -640,11 +634,11 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input and output formats match when not forcing', function (_t, done) {
|
||||
it('Input and output formats match when not forcing', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.png({ compressionLevel: 1, force: false })
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -653,44 +647,42 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Can force output format with output chaining', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Can force output format with output chaining', () => sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.png({ force: true })
|
||||
.jpeg({ force: false })
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (out) {
|
||||
.then((out) => {
|
||||
assert.strictEqual('png', out.info.format);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('toFormat=JPEG takes precedence over WebP extension', function (_t, done) {
|
||||
it('toFormat=JPEG takes precedence over WebP extension', (_t, done) => {
|
||||
const outputWebP = fixtures.path('output.webp');
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(8)
|
||||
.jpeg()
|
||||
.toFile(outputWebP, function (err, info) {
|
||||
.toFile(outputWebP, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
fs.rm(outputWebP, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('toFormat=WebP takes precedence over JPEG extension', function (_t, done) {
|
||||
it('toFormat=WebP takes precedence over JPEG extension', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(8)
|
||||
.webp()
|
||||
.toFile(outputJpg, function (err, info) {
|
||||
.toFile(outputJpg, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Load Vips V file', function (_t, done) {
|
||||
it('Load Vips V file', (_t, done) => {
|
||||
sharp(fixtures.inputV)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -700,11 +692,11 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Save Vips V file', function (_t, done) {
|
||||
it('Save Vips V file', (_t, done) => {
|
||||
const outputV = fixtures.path('output.v');
|
||||
sharp(fixtures.inputJpg)
|
||||
.extract({ left: 910, top: 1105, width: 70, height: 60 })
|
||||
.toFile(outputV, function (err, info) {
|
||||
.toFile(outputV, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('v', info.format);
|
||||
@ -827,62 +819,62 @@ describe('Input/output', function () {
|
||||
);
|
||||
});
|
||||
|
||||
describe('Input options', function () {
|
||||
it('Option-less', function () {
|
||||
describe('Input options', () => {
|
||||
it('Option-less', () => {
|
||||
sharp();
|
||||
});
|
||||
it('Ignore unknown attribute', function () {
|
||||
it('Ignore unknown attribute', () => {
|
||||
sharp({ unknown: true });
|
||||
});
|
||||
it('undefined with options fails', function () {
|
||||
assert.throws(function () {
|
||||
it('undefined with options fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp(undefined, {});
|
||||
}, /Unsupported input 'undefined' of type undefined when also providing options of type object/);
|
||||
});
|
||||
it('null with options fails', function () {
|
||||
assert.throws(function () {
|
||||
it('null with options fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp(null, {});
|
||||
}, /Unsupported input 'null' of type object when also providing options of type object/);
|
||||
});
|
||||
it('Non-Object options fails', function () {
|
||||
assert.throws(function () {
|
||||
it('Non-Object options fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp('test', 'zoinks');
|
||||
}, /Invalid input options zoinks/);
|
||||
});
|
||||
it('Invalid density: string', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid density: string', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ density: 'zoinks' });
|
||||
}, /Expected number between 1 and 100000 for density but received zoinks of type string/);
|
||||
});
|
||||
it('Invalid ignoreIcc: string', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid ignoreIcc: string', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ ignoreIcc: 'zoinks' });
|
||||
}, /Expected boolean for ignoreIcc but received zoinks of type string/);
|
||||
});
|
||||
it('Setting animated property updates pages property', function () {
|
||||
it('Setting animated property updates pages property', () => {
|
||||
assert.strictEqual(sharp({ animated: false }).options.input.pages, 1);
|
||||
assert.strictEqual(sharp({ animated: true }).options.input.pages, -1);
|
||||
});
|
||||
it('Invalid animated property throws', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid animated property throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ animated: -1 });
|
||||
}, /Expected boolean for animated but received -1 of type number/);
|
||||
});
|
||||
it('Invalid page property throws', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid page property throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ page: -1 });
|
||||
}, /Expected integer between 0 and 100000 for page but received -1 of type number/);
|
||||
});
|
||||
it('Invalid pages property throws', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid pages property throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ pages: '1' });
|
||||
}, /Expected integer between -1 and 100000 for pages but received 1 of type string/);
|
||||
});
|
||||
it('Valid openSlide.level property', function () {
|
||||
it('Valid openSlide.level property', () => {
|
||||
sharp({ openSlide: { level: 1 } });
|
||||
sharp({ level: 1 });
|
||||
});
|
||||
it('Invalid openSlide.level property (string) throws', function () {
|
||||
it('Invalid openSlide.level property (string) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ openSlide: { level: '1' } }),
|
||||
/Expected integer between 0 and 256 for openSlide.level but received 1 of type string/
|
||||
@ -892,7 +884,7 @@ describe('Input/output', function () {
|
||||
/Expected integer between 0 and 256 for level but received 1 of type string/
|
||||
);
|
||||
});
|
||||
it('Invalid openSlide.level property (negative) throws', function () {
|
||||
it('Invalid openSlide.level property (negative) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ openSlide: { level: -1 } }),
|
||||
/Expected integer between 0 and 256 for openSlide\.level but received -1 of type number/
|
||||
@ -902,11 +894,11 @@ describe('Input/output', function () {
|
||||
/Expected integer between 0 and 256 for level but received -1 of type number/
|
||||
);
|
||||
});
|
||||
it('Valid tiff.subifd property', function () {
|
||||
it('Valid tiff.subifd property', () => {
|
||||
sharp({ tiff: { subifd: 1 } });
|
||||
sharp({ subifd: 1 });
|
||||
});
|
||||
it('Invalid tiff.subifd property (string) throws', function () {
|
||||
it('Invalid tiff.subifd property (string) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ tiff: { subifd: '1' } }),
|
||||
/Expected integer between -1 and 100000 for tiff\.subifd but received 1 of type string/
|
||||
@ -916,7 +908,7 @@ describe('Input/output', function () {
|
||||
/Expected integer between -1 and 100000 for subifd but received 1 of type string/
|
||||
);
|
||||
});
|
||||
it('Invalid tiff.subifd property (float) throws', function () {
|
||||
it('Invalid tiff.subifd property (float) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ tiff: { subifd: 1.2 } }),
|
||||
/Expected integer between -1 and 100000 for tiff\.subifd but received 1.2 of type number/
|
||||
@ -926,15 +918,15 @@ describe('Input/output', function () {
|
||||
/Expected integer between -1 and 100000 for subifd but received 1.2 of type number/
|
||||
);
|
||||
});
|
||||
it('Valid pdf.background property (string)', function () {
|
||||
it('Valid pdf.background property (string)', () => {
|
||||
sharp({ pdf: { background: '#00ff00' } });
|
||||
sharp({ pdfBackground: '#00ff00' });
|
||||
});
|
||||
it('Valid pdf.background property (object)', function () {
|
||||
it('Valid pdf.background property (object)', () => {
|
||||
sharp({ pdf: { background: { r: 0, g: 255, b: 0 } } });
|
||||
sharp({ pdfBackground: { r: 0, g: 255, b: 0 } });
|
||||
});
|
||||
it('Invalid pdf.background property (string) throws', function () {
|
||||
it('Invalid pdf.background property (string) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ pdf: { background: '00ff00' } }),
|
||||
/Unable to parse color from string/
|
||||
@ -944,7 +936,7 @@ describe('Input/output', function () {
|
||||
/Unable to parse color from string/
|
||||
);
|
||||
});
|
||||
it('Invalid pdf.background property (number) throws', function () {
|
||||
it('Invalid pdf.background property (number) throws', () => {
|
||||
assert.throws(
|
||||
() => sharp({ pdf: { background: 255 } }),
|
||||
/Expected object or string for background/
|
||||
@ -954,7 +946,7 @@ describe('Input/output', function () {
|
||||
/Expected object or string for background/
|
||||
);
|
||||
});
|
||||
it('Invalid pdf.background property (object)', function () {
|
||||
it('Invalid pdf.background property (object)', () => {
|
||||
assert.throws(
|
||||
() => sharp({ pdf: { background: { red: 0, green: 255, blue: 0 } } }),
|
||||
/Unable to parse color from object/
|
||||
@ -979,8 +971,8 @@ describe('Input/output', function () {
|
||||
);
|
||||
});
|
||||
|
||||
describe('create new image', function () {
|
||||
it('RGB', function (_t, done) {
|
||||
describe('create new image', () => {
|
||||
it('RGB', (_t, done) => {
|
||||
const create = {
|
||||
width: 10,
|
||||
height: 20,
|
||||
@ -989,7 +981,7 @@ describe('Input/output', function () {
|
||||
};
|
||||
sharp({ create })
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(create.width, info.width);
|
||||
assert.strictEqual(create.height, info.height);
|
||||
@ -998,7 +990,7 @@ describe('Input/output', function () {
|
||||
fixtures.assertSimilar(fixtures.expected('create-rgb.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
it('RGBA', function (_t, done) {
|
||||
it('RGBA', (_t, done) => {
|
||||
const create = {
|
||||
width: 20,
|
||||
height: 10,
|
||||
@ -1007,7 +999,7 @@ describe('Input/output', function () {
|
||||
};
|
||||
sharp({ create })
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(create.width, info.width);
|
||||
assert.strictEqual(create.height, info.height);
|
||||
@ -1016,40 +1008,40 @@ describe('Input/output', function () {
|
||||
fixtures.assertSimilar(fixtures.expected('create-rgba.png'), data, done);
|
||||
});
|
||||
});
|
||||
it('Invalid channels', function () {
|
||||
it('Invalid channels', () => {
|
||||
const create = {
|
||||
width: 10,
|
||||
height: 20,
|
||||
channels: 2,
|
||||
background: { r: 0, g: 0, b: 0 }
|
||||
};
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp({ create });
|
||||
});
|
||||
});
|
||||
it('Missing background', function () {
|
||||
it('Missing background', () => {
|
||||
const create = {
|
||||
width: 10,
|
||||
height: 20,
|
||||
channels: 3
|
||||
};
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp({ create });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Queue length change events', function (_t, done) {
|
||||
it('Queue length change events', (_t, done) => {
|
||||
let eventCounter = 0;
|
||||
const queueListener = function (queueLength) {
|
||||
const queueListener = (queueLength) => {
|
||||
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
||||
eventCounter++;
|
||||
};
|
||||
sharp.queue.on('change', queueListener);
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err) {
|
||||
process.nextTick(function () {
|
||||
.toBuffer((err) => {
|
||||
process.nextTick(() => {
|
||||
sharp.queue.removeListener('change', queueListener);
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2, eventCounter);
|
||||
@ -1058,19 +1050,19 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Info event data', function (_t, done) {
|
||||
it('Info event data', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
const inPipeline = sharp()
|
||||
.resize(840, 472)
|
||||
.raw()
|
||||
.on('info', function (info) {
|
||||
.on('info', (info) => {
|
||||
assert.strictEqual(840, info.width);
|
||||
assert.strictEqual(472, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
});
|
||||
const badPipeline = sharp({ raw: { width: 840, height: 500, channels: 3 } })
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(err.message.indexOf('memory area too small') > 0, true);
|
||||
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||
const inPipeline = sharp()
|
||||
|
||||
@ -9,7 +9,7 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Join input images together', function () {
|
||||
describe('Join input images together', () => {
|
||||
it('Join two images horizontally', async () => {
|
||||
const data = await sharp([
|
||||
fixtures.inputPngPalette,
|
||||
|
||||
@ -10,13 +10,13 @@ const fs = require('node:fs');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Image channel insertion', function () {
|
||||
it('Grayscale to RGB, buffer', function (_t, done) {
|
||||
describe('Image channel insertion', () => {
|
||||
it('Grayscale to RGB, buffer', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> red
|
||||
.resize(320, 240)
|
||||
.joinChannel(fixtures.inputPngTestJoinChannel) // new green channel
|
||||
.joinChannel(fixtures.inputPngStripesH) // new blue channel
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -25,12 +25,12 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale to RGB, file', function (_t, done) {
|
||||
it('Grayscale to RGB, file', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> red
|
||||
.resize(320, 240)
|
||||
.joinChannel(fs.readFileSync(fixtures.inputPngTestJoinChannel)) // new green channel
|
||||
.joinChannel(fs.readFileSync(fixtures.inputPngStripesH)) // new blue channel
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -39,7 +39,7 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale to RGBA, buffer', function (_t, done) {
|
||||
it('Grayscale to RGBA, buffer', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> red
|
||||
.resize(320, 240)
|
||||
.joinChannel([
|
||||
@ -48,7 +48,7 @@ describe('Image channel insertion', function () {
|
||||
fixtures.inputPngStripesV
|
||||
]) // new green + blue + alpha channel
|
||||
.toColourspace(sharp.colourspace.srgb)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -57,7 +57,7 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale to RGBA, file', function (_t, done) {
|
||||
it('Grayscale to RGBA, file', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> red
|
||||
.resize(320, 240)
|
||||
.joinChannel([
|
||||
@ -66,7 +66,7 @@ describe('Image channel insertion', function () {
|
||||
fs.readFileSync(fixtures.inputPngStripesV) // new alpha channel
|
||||
])
|
||||
.toColourspace('srgb')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -75,7 +75,7 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale to CMYK, buffers', function (_t, done) {
|
||||
it('Grayscale to CMYK, buffers', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> magenta
|
||||
.resize(320, 240)
|
||||
.joinChannel([
|
||||
@ -85,7 +85,7 @@ describe('Image channel insertion', function () {
|
||||
])
|
||||
.toColorspace('cmyk')
|
||||
.toFormat('jpeg')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -94,12 +94,12 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Join raw buffers to RGB', function (_t, done) {
|
||||
it('Join raw buffers to RGB', (_t, done) => {
|
||||
Promise.all([
|
||||
sharp(fixtures.inputPngTestJoinChannel).toColourspace('b-w').raw().toBuffer(),
|
||||
sharp(fixtures.inputPngStripesH).toColourspace('b-w').raw().toBuffer()
|
||||
])
|
||||
.then(function (buffers) {
|
||||
.then((buffers) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.joinChannel(buffers, {
|
||||
@ -109,7 +109,7 @@ describe('Image channel insertion', function () {
|
||||
channels: 1
|
||||
}
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -117,12 +117,12 @@ describe('Image channel insertion', function () {
|
||||
fixtures.assertSimilar(fixtures.expected('joinChannel-rgb.jpg'), data, done);
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale to RGBA, files, two arrays', function (_t, done) {
|
||||
it('Grayscale to RGBA, files, two arrays', (_t, done) => {
|
||||
sharp(fixtures.inputPng) // gray -> red
|
||||
.resize(320, 240)
|
||||
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel)]) // new green channel
|
||||
@ -131,7 +131,7 @@ describe('Image channel insertion', function () {
|
||||
fs.readFileSync(fixtures.inputPngStripesV) // new alpha channel
|
||||
])
|
||||
.toColourspace('srgb')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -140,20 +140,20 @@ describe('Image channel insertion', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid raw buffer description', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid raw buffer description', () => {
|
||||
assert.throws(() => {
|
||||
sharp().joinChannel(fs.readFileSync(fixtures.inputPng), { raw: {} });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid input', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid input', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).joinChannel(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('No arguments', function () {
|
||||
assert.throws(function () {
|
||||
it('No arguments', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).joinChannel();
|
||||
});
|
||||
});
|
||||
|
||||
@ -49,15 +49,15 @@ describe('JP2 output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('JP2 quality', function (done) {
|
||||
it('JP2 quality', (done) => {
|
||||
sharp(fixtures.inputJp2)
|
||||
.resize(320, 240)
|
||||
.jp2({ quality: 70 })
|
||||
.toBuffer(function (err, buffer70) {
|
||||
.toBuffer((err, buffer70) => {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJp2)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, buffer80) {
|
||||
.toBuffer((err, buffer80) => {
|
||||
if (err) throw err;
|
||||
assert(buffer70.length < buffer80.length);
|
||||
done();
|
||||
@ -65,12 +65,12 @@ describe('JP2 output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Without chroma subsampling generates larger file', function (done) {
|
||||
it('Without chroma subsampling generates larger file', (done) => {
|
||||
// First generate with chroma subsampling (default)
|
||||
sharp(fixtures.inputJp2)
|
||||
.resize(320, 240)
|
||||
.jp2({ chromaSubsampling: '4:2:0' })
|
||||
.toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) {
|
||||
.toBuffer((err, withChromaSubsamplingData, withChromaSubsamplingInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withChromaSubsamplingData.length > 0);
|
||||
assert.strictEqual(withChromaSubsamplingData.length, withChromaSubsamplingInfo.size);
|
||||
@ -81,7 +81,7 @@ describe('JP2 output', () => {
|
||||
sharp(fixtures.inputJp2)
|
||||
.resize(320, 240)
|
||||
.jp2({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) {
|
||||
.toBuffer((err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutChromaSubsamplingData.length > 0);
|
||||
assert.strictEqual(withoutChromaSubsamplingData.length, withoutChromaSubsamplingInfo.size);
|
||||
|
||||
@ -9,21 +9,21 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('JPEG', function () {
|
||||
it('JPEG quality', function (_t, done) {
|
||||
describe('JPEG', () => {
|
||||
it('JPEG quality', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ quality: 70 })
|
||||
.toBuffer(function (err, buffer70) {
|
||||
.toBuffer((err, buffer70) => {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, buffer80) {
|
||||
.toBuffer((err, buffer80) => {
|
||||
if (err) throw err;
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ quality: 90 })
|
||||
.toBuffer(function (err, buffer90) {
|
||||
.toBuffer((err, buffer90) => {
|
||||
if (err) throw err;
|
||||
assert(buffer70.length < buffer80.length);
|
||||
assert(buffer80.length < buffer90.length);
|
||||
@ -33,31 +33,31 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid JPEG quality', function () {
|
||||
[-1, 88.2, 'test'].forEach(function (quality) {
|
||||
it(quality.toString(), function () {
|
||||
assert.throws(function () {
|
||||
describe('Invalid JPEG quality', () => {
|
||||
[-1, 88.2, 'test'].forEach((quality) => {
|
||||
it(quality.toString(), () => {
|
||||
assert.throws(() => {
|
||||
sharp().jpeg({ quality });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid JPEG quantisation table', function () {
|
||||
[-1, 88.2, 'test'].forEach(function (table) {
|
||||
it(table.toString(), function () {
|
||||
assert.throws(function () {
|
||||
describe('Invalid JPEG quantisation table', () => {
|
||||
[-1, 88.2, 'test'].forEach((table) => {
|
||||
it(table.toString(), () => {
|
||||
assert.throws(() => {
|
||||
sharp().jpeg({ quantisationTable: table });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Progressive JPEG image', function (_t, done) {
|
||||
it('Progressive JPEG image', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ progressive: false })
|
||||
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
||||
.toBuffer((err, nonProgressiveData, nonProgressiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, nonProgressiveData.length > 0);
|
||||
assert.strictEqual(nonProgressiveData.length, nonProgressiveInfo.size);
|
||||
@ -67,7 +67,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ progressive: true })
|
||||
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
||||
.toBuffer((err, progressiveData, progressiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, progressiveData.length > 0);
|
||||
assert.strictEqual(progressiveData.length, progressiveInfo.size);
|
||||
@ -80,12 +80,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Without chroma subsampling generates larger file', function (_t, done) {
|
||||
it('Without chroma subsampling generates larger file', (_t, done) => {
|
||||
// First generate with chroma subsampling (default)
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ chromaSubsampling: '4:2:0' })
|
||||
.toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) {
|
||||
.toBuffer((err, withChromaSubsamplingData, withChromaSubsamplingInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withChromaSubsamplingData.length > 0);
|
||||
assert.strictEqual(withChromaSubsamplingData.length, withChromaSubsamplingInfo.size);
|
||||
@ -96,7 +96,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) {
|
||||
.toBuffer((err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutChromaSubsamplingData.length > 0);
|
||||
assert.strictEqual(withoutChromaSubsamplingData.length, withoutChromaSubsamplingInfo.size);
|
||||
@ -109,18 +109,18 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid JPEG chromaSubsampling value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid JPEG chromaSubsampling value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().jpeg({ chromaSubsampling: '4:2:2' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Trellis quantisation', function (_t, done) {
|
||||
it('Trellis quantisation', (_t, done) => {
|
||||
// First generate without
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ trellisQuantisation: false })
|
||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||
.toBuffer((err, withoutData, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutData.length > 0);
|
||||
assert.strictEqual(withoutData.length, withoutInfo.size);
|
||||
@ -131,7 +131,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ trellisQuantization: true })
|
||||
.toBuffer(function (err, withData, withInfo) {
|
||||
.toBuffer((err, withData, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withData.length > 0);
|
||||
assert.strictEqual(withData.length, withInfo.size);
|
||||
@ -145,12 +145,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Overshoot deringing', function (_t, done) {
|
||||
it('Overshoot deringing', (_t, done) => {
|
||||
// First generate without
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ overshootDeringing: false })
|
||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||
.toBuffer((err, withoutData, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutData.length > 0);
|
||||
assert.strictEqual(withoutData.length, withoutInfo.size);
|
||||
@ -161,7 +161,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ overshootDeringing: true })
|
||||
.toBuffer(function (err, withData, withInfo) {
|
||||
.toBuffer((err, withData, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withData.length > 0);
|
||||
assert.strictEqual(withData.length, withInfo.size);
|
||||
@ -173,12 +173,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Optimise scans generates different output length', function (_t, done) {
|
||||
it('Optimise scans generates different output length', (_t, done) => {
|
||||
// First generate without
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimiseScans: false })
|
||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||
.toBuffer((err, withoutData, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutData.length > 0);
|
||||
assert.strictEqual(withoutData.length, withoutInfo.size);
|
||||
@ -189,7 +189,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimizeScans: true })
|
||||
.toBuffer(function (err, withData, withInfo) {
|
||||
.toBuffer((err, withData, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withData.length > 0);
|
||||
assert.strictEqual(withData.length, withInfo.size);
|
||||
@ -203,12 +203,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Optimise coding generates smaller output length', function (_t, done) {
|
||||
it('Optimise coding generates smaller output length', (_t, done) => {
|
||||
// First generate with optimize coding enabled (default)
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, withOptimiseCoding, withInfo) {
|
||||
.toBuffer((err, withOptimiseCoding, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withOptimiseCoding.length > 0);
|
||||
assert.strictEqual(withOptimiseCoding.length, withInfo.size);
|
||||
@ -219,7 +219,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimizeCoding: false })
|
||||
.toBuffer(function (err, withoutOptimiseCoding, withoutInfo) {
|
||||
.toBuffer((err, withoutOptimiseCoding, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutOptimiseCoding.length > 0);
|
||||
assert.strictEqual(withoutOptimiseCoding.length, withoutInfo.size);
|
||||
@ -233,12 +233,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Specifying quantisation table provides different JPEG', function (_t, done) {
|
||||
it('Specifying quantisation table provides different JPEG', (_t, done) => {
|
||||
// First generate with default quantisation table
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimiseCoding: false })
|
||||
.toBuffer(function (err, withDefaultQuantisationTable, withInfo) {
|
||||
.toBuffer((err, withDefaultQuantisationTable, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withDefaultQuantisationTable.length > 0);
|
||||
assert.strictEqual(withDefaultQuantisationTable.length, withInfo.size);
|
||||
@ -249,7 +249,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimiseCoding: false, quantisationTable: 3 })
|
||||
.toBuffer(function (err, withQuantTable3, withoutInfo) {
|
||||
.toBuffer((err, withQuantTable3, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withQuantTable3.length > 0);
|
||||
assert.strictEqual(withQuantTable3.length, withoutInfo.size);
|
||||
@ -264,12 +264,12 @@ describe('JPEG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Specifying quantization table provides different JPEG', function (_t, done) {
|
||||
it('Specifying quantization table provides different JPEG', (_t, done) => {
|
||||
// First generate with default quantization table
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimiseCoding: false })
|
||||
.toBuffer(function (err, withDefaultQuantizationTable, withInfo) {
|
||||
.toBuffer((err, withDefaultQuantizationTable, withInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withDefaultQuantizationTable.length > 0);
|
||||
assert.strictEqual(withDefaultQuantizationTable.length, withInfo.size);
|
||||
@ -280,7 +280,7 @@ describe('JPEG', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.jpeg({ optimiseCoding: false, quantizationTable: 3 })
|
||||
.toBuffer(function (err, withQuantTable3, withoutInfo) {
|
||||
.toBuffer((err, withQuantTable3, withoutInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withQuantTable3.length > 0);
|
||||
assert.strictEqual(withQuantTable3.length, withoutInfo.size);
|
||||
|
||||
@ -11,55 +11,55 @@ const libvips = require('../../lib/libvips');
|
||||
|
||||
const originalPlatform = process.platform;
|
||||
|
||||
const setPlatform = function (platform) {
|
||||
const setPlatform = (platform) => {
|
||||
Object.defineProperty(process, 'platform', { value: platform });
|
||||
};
|
||||
|
||||
const restorePlatform = function () {
|
||||
const restorePlatform = () => {
|
||||
setPlatform(originalPlatform);
|
||||
};
|
||||
|
||||
describe('libvips binaries', function () {
|
||||
describe('Windows platform', function () {
|
||||
before(function () { setPlatform('win32'); });
|
||||
describe('libvips binaries', () => {
|
||||
describe('Windows platform', () => {
|
||||
before(() => { setPlatform('win32'); });
|
||||
after(restorePlatform);
|
||||
|
||||
it('pkgConfigPath returns empty string', function () {
|
||||
it('pkgConfigPath returns empty string', () => {
|
||||
assert.strictEqual('', libvips.pkgConfigPath());
|
||||
});
|
||||
it('globalLibvipsVersion returns empty string', function () {
|
||||
it('globalLibvipsVersion returns empty string', () => {
|
||||
assert.strictEqual('', libvips.globalLibvipsVersion());
|
||||
});
|
||||
it('globalLibvipsVersion is always false', function () {
|
||||
it('globalLibvipsVersion is always false', () => {
|
||||
assert.strictEqual(false, libvips.useGlobalLibvips());
|
||||
});
|
||||
});
|
||||
|
||||
describe('non-Windows platforms', function () {
|
||||
before(function () { setPlatform('linux'); });
|
||||
describe('non-Windows platforms', () => {
|
||||
before(() => { setPlatform('linux'); });
|
||||
after(restorePlatform);
|
||||
|
||||
it('pkgConfigPath returns a string', function () {
|
||||
it('pkgConfigPath returns a string', () => {
|
||||
const pkgConfigPath = libvips.pkgConfigPath();
|
||||
assert.strictEqual('string', typeof pkgConfigPath);
|
||||
});
|
||||
it('globalLibvipsVersion returns a string', function () {
|
||||
it('globalLibvipsVersion returns a string', () => {
|
||||
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
||||
assert.strictEqual('string', typeof globalLibvipsVersion);
|
||||
});
|
||||
it('globalLibvipsVersion returns a boolean', function () {
|
||||
it('globalLibvipsVersion returns a boolean', () => {
|
||||
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||
assert.strictEqual('boolean', typeof useGlobalLibvips);
|
||||
});
|
||||
});
|
||||
|
||||
describe('platform agnostic', function () {
|
||||
it('minimumLibvipsVersion returns a valid semver', function () {
|
||||
describe('platform agnostic', () => {
|
||||
it('minimumLibvipsVersion returns a valid semver', () => {
|
||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||
assert.strictEqual('string', typeof minimumLibvipsVersion);
|
||||
assert.notStrictEqual(null, semver.valid(minimumLibvipsVersion));
|
||||
});
|
||||
it('useGlobalLibvips can be ignored via an env var', function () {
|
||||
it('useGlobalLibvips can be ignored via an env var', () => {
|
||||
process.env.SHARP_IGNORE_GLOBAL_LIBVIPS = 1;
|
||||
|
||||
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||
@ -67,14 +67,14 @@ describe('libvips binaries', function () {
|
||||
|
||||
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
||||
});
|
||||
it('useGlobalLibvips can be forced via an env var', function () {
|
||||
it('useGlobalLibvips can be forced via an env var', () => {
|
||||
process.env.SHARP_FORCE_GLOBAL_LIBVIPS = 1;
|
||||
|
||||
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||
assert.strictEqual(true, useGlobalLibvips);
|
||||
|
||||
let logged = false;
|
||||
const logger = function (message) {
|
||||
const logger = (message) => {
|
||||
assert.strictEqual(message, 'Detected SHARP_FORCE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
|
||||
logged = true;
|
||||
};
|
||||
@ -146,25 +146,25 @@ describe('libvips binaries', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('logger', function () {
|
||||
describe('logger', () => {
|
||||
const consoleLog = console.log;
|
||||
const consoleError = console.error;
|
||||
|
||||
after(function () {
|
||||
after(() => {
|
||||
console.log = consoleLog;
|
||||
console.error = consoleError;
|
||||
});
|
||||
|
||||
it('logs an info message', function (_t, done) {
|
||||
console.log = function (msg) {
|
||||
it('logs an info message', (_t, done) => {
|
||||
console.log = (msg) => {
|
||||
assert.strictEqual(msg, 'sharp: progress');
|
||||
done();
|
||||
};
|
||||
libvips.log('progress');
|
||||
});
|
||||
|
||||
it('logs an error message', function (_t, done) {
|
||||
console.error = function (msg) {
|
||||
it('logs an error message', (_t, done) => {
|
||||
console.error = (msg) => {
|
||||
assert.strictEqual(msg, 'sharp: Installation error: problem');
|
||||
done();
|
||||
};
|
||||
|
||||
@ -9,82 +9,82 @@ const fixtures = require('../fixtures');
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
describe('Linear adjustment', function () {
|
||||
describe('Linear adjustment', () => {
|
||||
const blackPoint = 70;
|
||||
const whitePoint = 203;
|
||||
const a = 255 / (whitePoint - blackPoint);
|
||||
const b = -blackPoint * a;
|
||||
|
||||
it('applies linear levels adjustment w/o alpha ch', function (_t, done) {
|
||||
it('applies linear levels adjustment w/o alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(a, b)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-linear.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies slope level adjustment w/o alpha ch', function (_t, done) {
|
||||
it('applies slope level adjustment w/o alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(a)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-slope.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies offset level adjustment w/o alpha ch', function (_t, done) {
|
||||
it('applies offset level adjustment w/o alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.linear(null, b)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('low-contrast-offset.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies linear levels adjustment w alpha ch', function (_t, done) {
|
||||
it('applies linear levels adjustment w alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(240)
|
||||
.linear(a, b)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-linear.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies linear levels adjustment to 16-bit w alpha ch', function (_t, done) {
|
||||
it('applies linear levels adjustment to 16-bit w alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.linear(a, b)
|
||||
.png({ compressionLevel: 0 })
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('linear-16bit.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies slope level adjustment w alpha ch', function (_t, done) {
|
||||
it('applies slope level adjustment w alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(240)
|
||||
.linear(a)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-slope.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies offset level adjustment w alpha ch', function (_t, done) {
|
||||
it('applies offset level adjustment w alpha ch', (_t, done) => {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(240)
|
||||
.linear(null, b)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-offset.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('per channel level adjustment', function (_t, done) {
|
||||
it('per channel level adjustment', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.linear([0.25, 0.5, 0.75], [150, 100, 50]).toBuffer(function (err, data) {
|
||||
.linear([0.25, 0.5, 0.75], [150, 100, 50]).toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('linear-per-channel.jpg'), data, done);
|
||||
});
|
||||
@ -112,7 +112,7 @@ describe('Linear adjustment', function () {
|
||||
assert.strictEqual(depth, 'uchar');
|
||||
});
|
||||
|
||||
it('Invalid linear arguments', function () {
|
||||
it('Invalid linear arguments', () => {
|
||||
assert.throws(
|
||||
() => sharp().linear('foo'),
|
||||
/Expected number or array of numbers for a but received foo of type string/
|
||||
|
||||
@ -16,7 +16,7 @@ const raw = {
|
||||
channels: 1
|
||||
};
|
||||
|
||||
describe('Median filter', function () {
|
||||
describe('Median filter', () => {
|
||||
it('default window (3x3)', async () => {
|
||||
const data = await sharp(input, { raw })
|
||||
.median()
|
||||
|
||||
@ -14,9 +14,9 @@ const fixtures = require('../fixtures');
|
||||
|
||||
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
||||
|
||||
describe('Image metadata', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
||||
describe('Image metadata', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -37,8 +37,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG with EXIF/ICC', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) {
|
||||
it('JPEG with EXIF/ICC', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -70,8 +70,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG with IPTC/XMP', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithIptcAndXmp).metadata(function (err, metadata) {
|
||||
it('JPEG with IPTC/XMP', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithIptcAndXmp).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
// IPTC
|
||||
assert.strictEqual('object', typeof metadata.iptc);
|
||||
@ -88,8 +88,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF', function (_t, done) {
|
||||
sharp(fixtures.inputTiff).metadata(function (err, metadata) {
|
||||
it('TIFF', (_t, done) => {
|
||||
sharp(fixtures.inputTiff).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -115,8 +115,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Multipage TIFF', function (_t, done) {
|
||||
sharp(fixtures.inputTiffMultipage).metadata(function (err, metadata) {
|
||||
it('Multipage TIFF', (_t, done) => {
|
||||
sharp(fixtures.inputTiffMultipage).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -138,8 +138,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function (_t, done) {
|
||||
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
||||
it('PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPng).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -162,8 +162,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with comment', function (_t, done) {
|
||||
sharp(fixtures.inputPngTestJoinChannel).metadata(function (err, metadata) {
|
||||
it('PNG with comment', (_t, done) => {
|
||||
sharp(fixtures.inputPngTestJoinChannel).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -187,8 +187,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Transparent PNG', function (_t, done) {
|
||||
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
||||
it('Transparent PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -259,8 +259,8 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function (_t, done) {
|
||||
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||
it('WebP', (_t, done) => {
|
||||
sharp(fixtures.inputWebP).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -351,8 +351,8 @@ describe('Image metadata', function () {
|
||||
})
|
||||
);
|
||||
|
||||
it('GIF', function (_t, done) {
|
||||
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
||||
it('GIF', (_t, done) => {
|
||||
sharp(fixtures.inputGif).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('gif', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -371,8 +371,8 @@ describe('Image metadata', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('GIF grey+alpha', function (_t, done) {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) {
|
||||
it('GIF grey+alpha', (_t, done) => {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('gif', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -459,8 +459,8 @@ describe('Image metadata', function () {
|
||||
})
|
||||
);
|
||||
|
||||
it('File in, Promise out', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).metadata().then(function (metadata) {
|
||||
it('File in, Promise out', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).metadata().then((metadata) => {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@ -503,10 +503,10 @@ describe('Image metadata', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('Stream in, Promise out', function (_t, done) {
|
||||
it('Stream in, Promise out', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp();
|
||||
pipeline.metadata().then(function (metadata) {
|
||||
pipeline.metadata().then((metadata) => {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(829183, metadata.size);
|
||||
assert.strictEqual(2725, metadata.width);
|
||||
@ -554,9 +554,9 @@ describe('Image metadata', function () {
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('Stream', function (_t, done) {
|
||||
it('Stream', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().metadata(function (err, metadata) {
|
||||
const pipeline = sharp().metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual(829183, metadata.size);
|
||||
@ -578,9 +578,9 @@ describe('Image metadata', function () {
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Resize to half width using metadata', function (_t, done) {
|
||||
it('Resize to half width using metadata', (_t, done) => {
|
||||
const image = sharp(fixtures.inputJpg);
|
||||
image.metadata(function (err, metadata) {
|
||||
image.metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('undefined', typeof metadata.size);
|
||||
@ -597,7 +597,7 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
assert.strictEqual('undefined', typeof metadata.exif);
|
||||
assert.strictEqual('undefined', typeof metadata.icc);
|
||||
image.resize(Math.floor(metadata.width / 2)).toBuffer(function (err, data, info) {
|
||||
image.resize(Math.floor(metadata.width / 2)).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(1362, info.width);
|
||||
@ -607,13 +607,13 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Keep EXIF metadata and add sRGB profile after a resize', function (_t, done) {
|
||||
it('Keep EXIF metadata and add sRGB profile after a resize', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320, 240)
|
||||
.withMetadata()
|
||||
.toBuffer(function (err, buffer) {
|
||||
.toBuffer((err, buffer) => {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
sharp(buffer).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, metadata.hasProfile);
|
||||
assert.strictEqual(8, metadata.orientation);
|
||||
@ -727,14 +727,14 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(undefined, metadata.icc);
|
||||
});
|
||||
|
||||
it('Apply CMYK output ICC profile', function (_t, done) {
|
||||
it('Apply CMYK output ICC profile', (_t, done) => {
|
||||
const output = fixtures.path('output.icc-cmyk.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(64)
|
||||
.withIccProfile('cmyk')
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) throw err;
|
||||
sharp(output).metadata(function (err, metadata) {
|
||||
sharp(output).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, metadata.hasProfile);
|
||||
assert.strictEqual('cmyk', metadata.space);
|
||||
@ -752,12 +752,12 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Apply custom output ICC profile', function (_t, done) {
|
||||
it('Apply custom output ICC profile', (_t, done) => {
|
||||
const output = fixtures.path('output.hilutite.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(64)
|
||||
.withIccProfile(fixtures.path('hilutite.icm'))
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('hilutite.jpg'), 9);
|
||||
done();
|
||||
@ -792,12 +792,12 @@ describe('Image metadata', function () {
|
||||
)
|
||||
);
|
||||
|
||||
it('Remove EXIF metadata after a resize', function (_t, done) {
|
||||
it('Remove EXIF metadata after a resize', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, buffer) {
|
||||
.toBuffer((err, buffer) => {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
sharp(buffer).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
@ -808,12 +808,12 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Remove metadata from PNG output', function (_t, done) {
|
||||
it('Remove metadata from PNG output', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.png()
|
||||
.toBuffer(function (err, buffer) {
|
||||
.toBuffer((err, buffer) => {
|
||||
if (err) throw err;
|
||||
sharp(buffer).metadata(function (err, metadata) {
|
||||
sharp(buffer).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||
@ -865,55 +865,41 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(density, 96);
|
||||
});
|
||||
|
||||
it('chromaSubsampling 4:4:4:4 CMYK JPEG', function () {
|
||||
return sharp(fixtures.inputJpgWithCmykProfile)
|
||||
it('chromaSubsampling 4:4:4:4 CMYK JPEG', () => sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual('4:4:4:4', metadata.chromaSubsampling);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('chromaSubsampling 4:4:4 RGB JPEG', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('chromaSubsampling 4:4:4 RGB JPEG', () => sharp(fixtures.inputJpg)
|
||||
.resize(10, 10)
|
||||
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||
.toBuffer()
|
||||
.then(function (data) {
|
||||
return sharp(data)
|
||||
.then((data) => sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual('4:4:4', metadata.chromaSubsampling);
|
||||
});
|
||||
});
|
||||
});
|
||||
})));
|
||||
|
||||
it('isProgressive JPEG', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('isProgressive JPEG', () => sharp(fixtures.inputJpg)
|
||||
.resize(10, 10)
|
||||
.jpeg({ progressive: true })
|
||||
.toBuffer()
|
||||
.then(function (data) {
|
||||
return sharp(data)
|
||||
.then((data) => sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual(true, metadata.isProgressive);
|
||||
});
|
||||
});
|
||||
});
|
||||
})));
|
||||
|
||||
it('isProgressive PNG', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('isProgressive PNG', () => sharp(fixtures.inputJpg)
|
||||
.resize(10, 10)
|
||||
.png({ progressive: true })
|
||||
.toBuffer()
|
||||
.then(function (data) {
|
||||
return sharp(data)
|
||||
.then((data) => sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual(true, metadata.isProgressive);
|
||||
});
|
||||
});
|
||||
});
|
||||
})));
|
||||
|
||||
it('16-bit TIFF with TIFFTAG_PHOTOSHOP metadata', () =>
|
||||
sharp(fixtures.inputTifftagPhotoshop)
|
||||
@ -995,18 +981,18 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(description, 'sP3C');
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('File input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.metadata(function (err) {
|
||||
.metadata((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
assert.ok(err.message.includes('Input file has corrupt header: VipsJpeg: premature end of'), err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('Buffer input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||
.metadata(function (err) {
|
||||
.metadata((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
assert.ok(err.message.includes('Input buffer has corrupt header: VipsJpeg: premature end of'), err);
|
||||
done();
|
||||
@ -1114,7 +1100,7 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(exif2.Image.Software, 'sharp');
|
||||
});
|
||||
|
||||
describe('XMP metadata tests', function () {
|
||||
describe('XMP metadata tests', () => {
|
||||
it('withMetadata preserves existing XMP metadata from input', async () => {
|
||||
const data = await sharp(fixtures.inputJpgWithIptcAndXmp)
|
||||
.resize(320, 240)
|
||||
@ -1256,21 +1242,21 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(true, xmpString.includes('image/webp'));
|
||||
});
|
||||
|
||||
it('withXmp XMP validation - non-string input', function () {
|
||||
it('withXmp XMP validation - non-string input', () => {
|
||||
assert.throws(
|
||||
() => sharp().withXmp(123),
|
||||
/Expected non-empty string for xmp but received 123 of type number/
|
||||
);
|
||||
});
|
||||
|
||||
it('withXmp XMP validation - null input', function () {
|
||||
it('withXmp XMP validation - null input', () => {
|
||||
assert.throws(
|
||||
() => sharp().withXmp(null),
|
||||
/Expected non-empty string for xmp but received null of type object/
|
||||
);
|
||||
});
|
||||
|
||||
it('withXmp XMP validation - empty string', function () {
|
||||
it('withXmp XMP validation - empty string', () => {
|
||||
assert.throws(
|
||||
() => sharp().withXmp(''),
|
||||
/Expected non-empty string for xmp/
|
||||
@ -1278,54 +1264,54 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid parameters', function () {
|
||||
it('String orientation', function () {
|
||||
assert.throws(function () {
|
||||
describe('Invalid parameters', () => {
|
||||
it('String orientation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ orientation: 'zoinks' });
|
||||
});
|
||||
});
|
||||
it('Negative orientation', function () {
|
||||
assert.throws(function () {
|
||||
it('Negative orientation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ orientation: -1 });
|
||||
});
|
||||
});
|
||||
it('Zero orientation', function () {
|
||||
assert.throws(function () {
|
||||
it('Zero orientation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ orientation: 0 });
|
||||
});
|
||||
});
|
||||
it('Too large orientation', function () {
|
||||
assert.throws(function () {
|
||||
it('Too large orientation', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ orientation: 9 });
|
||||
});
|
||||
});
|
||||
it('Non-numeric density', function () {
|
||||
assert.throws(function () {
|
||||
it('Non-numeric density', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ density: '1' });
|
||||
});
|
||||
});
|
||||
it('Negative density', function () {
|
||||
assert.throws(function () {
|
||||
it('Negative density', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ density: -1 });
|
||||
});
|
||||
});
|
||||
it('Non string icc', function () {
|
||||
assert.throws(function () {
|
||||
it('Non string icc', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ icc: true });
|
||||
});
|
||||
});
|
||||
it('Non object exif', function () {
|
||||
assert.throws(function () {
|
||||
it('Non object exif', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ exif: false });
|
||||
});
|
||||
});
|
||||
it('Non string value in object exif', function () {
|
||||
assert.throws(function () {
|
||||
it('Non string value in object exif', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ exif: { ifd0: false } });
|
||||
});
|
||||
});
|
||||
it('Non string value in nested object exif', function () {
|
||||
assert.throws(function () {
|
||||
it('Non string value in nested object exif', () => {
|
||||
assert.throws(() => {
|
||||
sharp().withMetadata({ exif: { ifd0: { fail: false } } });
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,8 +8,8 @@ const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Modulate', function () {
|
||||
describe('Invalid options', function () {
|
||||
describe('Modulate', () => {
|
||||
describe('Invalid options', () => {
|
||||
[
|
||||
null,
|
||||
undefined,
|
||||
@ -25,9 +25,9 @@ describe('Modulate', function () {
|
||||
{ hue: null },
|
||||
{ lightness: '+50' },
|
||||
{ lightness: null }
|
||||
].forEach(function (options) {
|
||||
it('should throw', function () {
|
||||
assert.throws(function () {
|
||||
].forEach((options) => {
|
||||
it('should throw', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).modulate(options);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,12 +9,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Negate', function () {
|
||||
it('negate (jpeg)', function (_t, done) {
|
||||
describe('Negate', () => {
|
||||
it('negate (jpeg)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -23,11 +23,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png)', function (_t, done) {
|
||||
it('negate (png)', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -36,11 +36,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png, trans)', function (_t, done) {
|
||||
it('negate (png, trans)', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -49,11 +49,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (png, alpha)', function (_t, done) {
|
||||
it('negate (png, alpha)', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -62,11 +62,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (webp)', function (_t, done) {
|
||||
it('negate (webp)', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -75,11 +75,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (webp, trans)', function (_t, done) {
|
||||
it('negate (webp, trans)', (_t, done) => {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -88,11 +88,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (true)', function (_t, done) {
|
||||
it('negate (true)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate(true)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -101,22 +101,22 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate (false)', function (_t, done) {
|
||||
it('negate (false)', (_t, done) => {
|
||||
const output = fixtures.path('output.unmodified-by-negate.png');
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.negate(false)
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('negate ({alpha: true})', function (_t, done) {
|
||||
it('negate ({alpha: true})', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -125,11 +125,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate non-alpha channels (png)', function (_t, done) {
|
||||
it('negate non-alpha channels (png)', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -138,11 +138,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate non-alpha channels (png, trans)', function (_t, done) {
|
||||
it('negate non-alpha channels (png, trans)', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -151,11 +151,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate non-alpha channels (png, alpha)', function (_t, done) {
|
||||
it('negate non-alpha channels (png, alpha)', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -164,11 +164,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate non-alpha channels (webp)', function (_t, done) {
|
||||
it('negate non-alpha channels (webp)', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -177,11 +177,11 @@ describe('Negate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('negate non-alpha channels (webp, trans)', function (_t, done) {
|
||||
it('negate non-alpha channels (webp, trans)', (_t, done) => {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.resize(320, 240)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -206,8 +206,8 @@ describe('Negate', function () {
|
||||
assert.deepStrictEqual({ r, g, b }, { r: 245, g: 235, b: 225 });
|
||||
});
|
||||
|
||||
it('invalid alpha value', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid alpha value', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputWebPWithTransparency).negate({ alpha: 'non-bool' });
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,8 +9,8 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Gaussian noise', function () {
|
||||
it('generate single-channel gaussian noise', function (_t, done) {
|
||||
describe('Gaussian noise', () => {
|
||||
it('generate single-channel gaussian noise', (_t, done) => {
|
||||
const output = fixtures.path('output.noise-1-channel.png');
|
||||
const noise = sharp({
|
||||
create: {
|
||||
@ -24,13 +24,13 @@ describe('Gaussian noise', function () {
|
||||
}
|
||||
}
|
||||
}).toColourspace('b-w');
|
||||
noise.toFile(output, function (err, info) {
|
||||
noise.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(1024, info.width);
|
||||
assert.strictEqual(768, info.height);
|
||||
assert.strictEqual(1, info.channels);
|
||||
sharp(output).metadata(function (err, metadata) {
|
||||
sharp(output).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('b-w', metadata.space);
|
||||
assert.strictEqual('uchar', metadata.depth);
|
||||
@ -39,7 +39,7 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('generate 3-channels gaussian noise', function (_t, done) {
|
||||
it('generate 3-channels gaussian noise', (_t, done) => {
|
||||
const output = fixtures.path('output.noise-3-channels.png');
|
||||
const noise = sharp({
|
||||
create: {
|
||||
@ -53,13 +53,13 @@ describe('Gaussian noise', function () {
|
||||
}
|
||||
}
|
||||
});
|
||||
noise.toFile(output, function (err, info) {
|
||||
noise.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(1024, info.width);
|
||||
assert.strictEqual(768, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
sharp(output).metadata(function (err, metadata) {
|
||||
sharp(output).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual('uchar', metadata.depth);
|
||||
@ -68,7 +68,7 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('overlay 3-channels gaussian noise over image', function (_t, done) {
|
||||
it('overlay 3-channels gaussian noise over image', (_t, done) => {
|
||||
const output = fixtures.path('output.noise-image.jpg');
|
||||
const noise = sharp({
|
||||
create: {
|
||||
@ -82,7 +82,7 @@ describe('Gaussian noise', function () {
|
||||
}
|
||||
}
|
||||
});
|
||||
noise.toBuffer(function (err, data, info) {
|
||||
noise.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, info.channels);
|
||||
sharp(fixtures.inputJpg)
|
||||
@ -98,14 +98,14 @@ describe('Gaussian noise', function () {
|
||||
}
|
||||
}
|
||||
])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
// perceptual hashing detects that images are the same (difference is <=1%)
|
||||
fixtures.assertSimilar(output, fixtures.inputJpg, function (err) {
|
||||
fixtures.assertSimilar(output, fixtures.inputJpg, (err) => {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
@ -113,7 +113,7 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('overlay strong single-channel (sRGB) gaussian noise with 25% transparency over transparent png image', function (_t, done) {
|
||||
it('overlay strong single-channel (sRGB) gaussian noise with 25% transparency over transparent png image', (_t, done) => {
|
||||
const output = fixtures.path('output.noise-image-transparent.png');
|
||||
const width = 320;
|
||||
const height = 240;
|
||||
@ -136,14 +136,14 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
noise
|
||||
.toColourspace('b-w')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, info.channels);
|
||||
sharp(data, { raw: rawData })
|
||||
.joinChannel(data, { raw: rawData }) // r channel
|
||||
.joinChannel(data, { raw: rawData }) // b channel
|
||||
.joinChannel(Buffer.alloc(width * height, 64), { raw: rawData }) // alpha channel
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(4, info.channels);
|
||||
sharp(fixtures.inputPngRGBWithAlpha)
|
||||
@ -159,13 +159,13 @@ describe('Gaussian noise', function () {
|
||||
}
|
||||
}
|
||||
])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(width, info.width);
|
||||
assert.strictEqual(height, info.height);
|
||||
assert.strictEqual(4, info.channels);
|
||||
fixtures.assertSimilar(output, fixtures.inputPngRGBWithAlpha, { threshold: 10 }, function (err) {
|
||||
fixtures.assertSimilar(output, fixtures.inputPngRGBWithAlpha, { threshold: 10 }, (err) => {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
@ -194,16 +194,16 @@ describe('Gaussian noise', function () {
|
||||
assert.strictEqual(delay.length, 4);
|
||||
});
|
||||
|
||||
it('no create object properties specified', function () {
|
||||
assert.throws(function () {
|
||||
it('no create object properties specified', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid noise object', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid noise object', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
@ -215,8 +215,8 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown type of noise', function () {
|
||||
assert.throws(function () {
|
||||
it('unknown type of noise', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
@ -230,8 +230,8 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('gaussian noise, invalid amount of channels', function () {
|
||||
assert.throws(function () {
|
||||
it('gaussian noise, invalid amount of channels', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
@ -247,8 +247,8 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('gaussian noise, invalid mean', function () {
|
||||
assert.throws(function () {
|
||||
it('gaussian noise, invalid mean', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
@ -264,8 +264,8 @@ describe('Gaussian noise', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('gaussian noise, invalid sigma', function () {
|
||||
assert.throws(function () {
|
||||
it('gaussian noise, invalid sigma', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 100,
|
||||
|
||||
@ -9,7 +9,7 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
const assertNormalized = function (data) {
|
||||
const assertNormalized = (data) => {
|
||||
let min = 255;
|
||||
let max = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@ -20,48 +20,48 @@ const assertNormalized = function (data) {
|
||||
assert.ok(max > 248, 'max too low');
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
it('spreads rgb image values between 0 and 255', function (_t, done) {
|
||||
describe('Normalization', () => {
|
||||
it('spreads rgb image values between 0 and 255', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('spreads grayscaled image values between 0 and 255', function (_t, done) {
|
||||
it('spreads grayscaled image values between 0 and 255', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.greyscale()
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('stretches greyscale images with alpha channel', function (_t, done) {
|
||||
it('stretches greyscale images with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps an existing alpha channel', function (_t, done) {
|
||||
it('keeps an existing alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(8, 8)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
@ -71,13 +71,13 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the alpha channel of greyscale images intact', function (_t, done) {
|
||||
it('keeps the alpha channel of greyscale images intact', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(8, 8)
|
||||
.normalise()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) return done(err);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
@ -87,76 +87,76 @@ describe('Normalization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not alter images with only one color', function (_t, done) {
|
||||
it('does not alter images with only one color', (_t, done) => {
|
||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toFile(output, function (err) {
|
||||
.toFile(output, (err) => {
|
||||
if (err) done(err);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('works with 16-bit RGBA images', function (_t, done) {
|
||||
it('works with 16-bit RGBA images', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.normalise()
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle luminance range', function (_t, done) {
|
||||
it('should handle luminance range', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise({ lower: 10, upper: 70 })
|
||||
.raw()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow lower without upper', function () {
|
||||
it('should allow lower without upper', () => {
|
||||
assert.doesNotThrow(() => sharp().normalize({ lower: 2 }));
|
||||
});
|
||||
it('should allow upper without lower', function () {
|
||||
it('should allow upper without lower', () => {
|
||||
assert.doesNotThrow(() => sharp().normalize({ upper: 98 }));
|
||||
});
|
||||
it('should throw when lower is out of range', function () {
|
||||
it('should throw when lower is out of range', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: -10 }),
|
||||
/Expected number between 0 and 99 for lower but received -10 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is out of range', function () {
|
||||
it('should throw when upper is out of range', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 110 }),
|
||||
/Expected number between 1 and 100 for upper but received 110 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when lower is not a number', function () {
|
||||
it('should throw when lower is not a number', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 'fail' }),
|
||||
/Expected number between 0 and 99 for lower but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is not a number', function () {
|
||||
it('should throw when upper is not a number', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 'fail' }),
|
||||
/Expected number between 1 and 100 for upper but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower and upper are equal', function () {
|
||||
it('should throw when the lower and upper are equal', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 2, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 2 >= 2/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower is greater than upper', function () {
|
||||
it('should throw when the lower is greater than upper', () => {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 3, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 3 >= 2/
|
||||
|
||||
@ -10,25 +10,25 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('PNG', function () {
|
||||
it('compression level is valid', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
describe('PNG', () => {
|
||||
it('compression level is valid', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().png({ compressionLevel: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
it('compression level is invalid', function () {
|
||||
assert.throws(function () {
|
||||
it('compression level is invalid', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ compressionLevel: -1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('default compressionLevel generates smaller file than compressionLevel=0', function (_t, done) {
|
||||
it('default compressionLevel generates smaller file than compressionLevel=0', (_t, done) => {
|
||||
// First generate with default compressionLevel
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.png()
|
||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||
.toBuffer((err, defaultData, defaultInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, defaultData.length > 0);
|
||||
assert.strictEqual('png', defaultInfo.format);
|
||||
@ -36,7 +36,7 @@ describe('PNG', function () {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.png({ compressionLevel: 0 })
|
||||
.toBuffer(function (err, largerData, largerInfo) {
|
||||
.toBuffer((err, largerData, largerInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, largerData.length > 0);
|
||||
assert.strictEqual('png', largerInfo.format);
|
||||
@ -46,12 +46,12 @@ describe('PNG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('without adaptiveFiltering generates smaller file', function (_t, done) {
|
||||
it('without adaptiveFiltering generates smaller file', (_t, done) => {
|
||||
// First generate with adaptive filtering
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.png({ adaptiveFiltering: true })
|
||||
.toBuffer(function (err, adaptiveData, adaptiveInfo) {
|
||||
.toBuffer((err, adaptiveData, adaptiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, adaptiveData.length > 0);
|
||||
assert.strictEqual(adaptiveData.length, adaptiveInfo.size);
|
||||
@ -62,7 +62,7 @@ describe('PNG', function () {
|
||||
sharp(fixtures.inputPng)
|
||||
.resize(320, 240)
|
||||
.png({ adaptiveFiltering: false })
|
||||
.toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) {
|
||||
.toBuffer((err, withoutAdaptiveData, withoutAdaptiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, withoutAdaptiveData.length > 0);
|
||||
assert.strictEqual(withoutAdaptiveData.length, withoutAdaptiveInfo.size);
|
||||
@ -75,17 +75,17 @@ describe('PNG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG adaptiveFiltering value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG adaptiveFiltering value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ adaptiveFiltering: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Progressive PNG image', function (_t, done) {
|
||||
it('Progressive PNG image', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.png({ progressive: false })
|
||||
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
||||
.toBuffer((err, nonProgressiveData, nonProgressiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, nonProgressiveData.length > 0);
|
||||
assert.strictEqual(nonProgressiveData.length, nonProgressiveInfo.size);
|
||||
@ -94,7 +94,7 @@ describe('PNG', function () {
|
||||
assert.strictEqual(240, nonProgressiveInfo.height);
|
||||
sharp(nonProgressiveData)
|
||||
.png({ progressive: true })
|
||||
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
||||
.toBuffer((err, progressiveData, progressiveInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, progressiveData.length > 0);
|
||||
assert.strictEqual(progressiveData.length, progressiveInfo.size);
|
||||
@ -107,11 +107,11 @@ describe('PNG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit grey+alpha PNG identity transform', function () {
|
||||
it('16-bit grey+alpha PNG identity transform', () => {
|
||||
const actual = fixtures.path('output.16-bit-grey-alpha-identity.png');
|
||||
return sharp(fixtures.inputPng16BitGreyAlpha)
|
||||
.toFile(actual)
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
fixtures.assertMaxColourDistance(actual, fixtures.expected('16-bit-grey-alpha-identity.png'));
|
||||
});
|
||||
});
|
||||
@ -160,30 +160,30 @@ describe('PNG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid PNG libimagequant palette value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid PNG libimagequant palette value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().png({ palette: false });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG libimagequant palette value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG libimagequant palette value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ palette: 'fail' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid PNG libimagequant quality value produces image of same size or smaller', function () {
|
||||
it('Valid PNG libimagequant quality value produces image of same size or smaller', () => {
|
||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||
return Promise.all([
|
||||
sharp(inputPngBuffer).resize(10).png({ effort: 1, quality: 80 }).toBuffer(),
|
||||
sharp(inputPngBuffer).resize(10).png({ effort: 1, quality: 100 }).toBuffer()
|
||||
]).then(function (data) {
|
||||
]).then((data) => {
|
||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG libimagequant quality value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG libimagequant quality value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ quality: 101 });
|
||||
});
|
||||
});
|
||||
@ -194,24 +194,24 @@ describe('PNG', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid PNG libimagequant colours value produces image of same size or smaller', function () {
|
||||
it('Valid PNG libimagequant colours value produces image of same size or smaller', () => {
|
||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||
return Promise.all([
|
||||
sharp(inputPngBuffer).resize(10).png({ colours: 100 }).toBuffer(),
|
||||
sharp(inputPngBuffer).resize(10).png({ colours: 200 }).toBuffer()
|
||||
]).then(function (data) {
|
||||
]).then((data) => {
|
||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG libimagequant colours value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG libimagequant colours value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ colours: -1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG libimagequant colors value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG libimagequant colors value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ colors: 0.1 });
|
||||
});
|
||||
});
|
||||
@ -235,18 +235,18 @@ describe('PNG', function () {
|
||||
assert.strictEqual(space, 'b-w');
|
||||
});
|
||||
|
||||
it('Valid PNG libimagequant dither value produces image of same size or smaller', function () {
|
||||
it('Valid PNG libimagequant dither value produces image of same size or smaller', () => {
|
||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||
return Promise.all([
|
||||
sharp(inputPngBuffer).resize(10).png({ dither: 0.1 }).toBuffer(),
|
||||
sharp(inputPngBuffer).resize(10).png({ dither: 0.9 }).toBuffer()
|
||||
]).then(function (data) {
|
||||
]).then((data) => {
|
||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid PNG libimagequant dither value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid PNG libimagequant dither value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().png({ dither: 'fail' });
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,49 +9,49 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Raw pixel data', function () {
|
||||
describe('Raw pixel input', function () {
|
||||
it('Empty data', function () {
|
||||
assert.throws(function () {
|
||||
describe('Raw pixel data', () => {
|
||||
describe('Raw pixel input', () => {
|
||||
it('Empty data', () => {
|
||||
assert.throws(() => {
|
||||
sharp(Buffer.from(''));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(new ArrayBuffer(0));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(new Uint8Array(0));
|
||||
}, /empty/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp(new Uint8ClampedArray(0));
|
||||
}, /empty/);
|
||||
});
|
||||
|
||||
it('Missing options', function () {
|
||||
assert.throws(function () {
|
||||
it('Missing options', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ raw: {} });
|
||||
});
|
||||
});
|
||||
|
||||
it('Incomplete options', function () {
|
||||
assert.throws(function () {
|
||||
it('Incomplete options', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ raw: { width: 1, height: 1 } });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid channels', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid channels', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ raw: { width: 1, height: 1, channels: 5 } });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid height', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid height', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ raw: { width: 1, height: 0, channels: 4 } });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid width', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid width', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ raw: { width: 'zoinks', height: 1, channels: 4 } });
|
||||
});
|
||||
});
|
||||
@ -85,12 +85,12 @@ describe('Raw pixel data', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('RGB', function (_t, done) {
|
||||
it('RGB', (_t, done) => {
|
||||
// Convert to raw pixel data
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(256)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(209, info.height);
|
||||
@ -104,7 +104,7 @@ describe('Raw pixel data', function () {
|
||||
}
|
||||
})
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(209, info.height);
|
||||
@ -114,12 +114,12 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('RGBA', function (_t, done) {
|
||||
it('RGBA', (_t, done) => {
|
||||
// Convert to raw pixel data
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(256)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(192, info.height);
|
||||
@ -133,7 +133,7 @@ describe('Raw pixel data', function () {
|
||||
}
|
||||
})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(192, info.height);
|
||||
@ -143,12 +143,12 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('RGBA premultiplied', function (_t, done) {
|
||||
it('RGBA premultiplied', (_t, done) => {
|
||||
// Convert to raw pixel data
|
||||
sharp(fixtures.inputPngSolidAlpha)
|
||||
.resize(256)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(192, info.height);
|
||||
@ -178,7 +178,7 @@ describe('Raw pixel data', function () {
|
||||
}
|
||||
})
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(256, info.width);
|
||||
assert.strictEqual(192, info.height);
|
||||
@ -189,7 +189,7 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG to raw Stream and back again', function (_t, done) {
|
||||
it('JPEG to raw Stream and back again', (_t, done) => {
|
||||
const width = 32;
|
||||
const height = 24;
|
||||
const writable = sharp({
|
||||
@ -201,7 +201,7 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
writable
|
||||
.jpeg()
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(32, info.width);
|
||||
@ -215,13 +215,13 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Output raw, uncompressed image data', function () {
|
||||
it('1 channel greyscale image', function (_t, done) {
|
||||
describe('Output raw, uncompressed image data', () => {
|
||||
it('1 channel greyscale image', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.greyscale()
|
||||
.resize(32, 24)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 1, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -233,11 +233,11 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('3 channel colour image without transparency', function (_t, done) {
|
||||
it('3 channel colour image without transparency', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(32, 24)
|
||||
.toFormat('raw')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 3, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -248,11 +248,11 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('4 channel colour image with transparency', function (_t, done) {
|
||||
it('4 channel colour image with transparency', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(32, 24)
|
||||
.toFormat(sharp.format.raw)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(32 * 24 * 4, info.size);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -278,9 +278,9 @@ describe('Raw pixel data', function () {
|
||||
);
|
||||
});
|
||||
|
||||
describe('Raw pixel depths', function () {
|
||||
it('Invalid depth', function () {
|
||||
assert.throws(function () {
|
||||
describe('Raw pixel depths', () => {
|
||||
it('Invalid depth', () => {
|
||||
assert.throws(() => {
|
||||
sharp(Buffer.alloc(3), { raw: { width: 1, height: 1, channels: 3 } })
|
||||
.raw({ depth: 'zoinks' });
|
||||
});
|
||||
|
||||
@ -15,12 +15,12 @@ const sepia = [
|
||||
[0.2392, 0.4696, 0.0912]
|
||||
];
|
||||
|
||||
describe('Recomb', function () {
|
||||
it('applies a sepia filter using recomb', function (_t, done) {
|
||||
describe('Recomb', () => {
|
||||
it('applies a sepia filter using recomb', (_t, done) => {
|
||||
const output = fixtures.path('output.recomb-sepia.jpg');
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
.recomb(sepia)
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(600, info.width);
|
||||
@ -34,11 +34,11 @@ describe('Recomb', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('applies a sepia filter using recomb to an PNG with Alpha', function (_t, done) {
|
||||
it('applies a sepia filter using recomb to an PNG with Alpha', (_t, done) => {
|
||||
const output = fixtures.path('output.recomb-sepia.png');
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.recomb(sepia)
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(1024, info.width);
|
||||
@ -66,7 +66,7 @@ describe('Recomb', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
});
|
||||
|
||||
it('applies a different sepia filter using recomb', function (_t, done) {
|
||||
it('applies a different sepia filter using recomb', (_t, done) => {
|
||||
const output = fixtures.path('output.recomb-sepia2.jpg');
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
.recomb([
|
||||
@ -74,7 +74,7 @@ describe('Recomb', function () {
|
||||
[0.349, 0.686, 0.168],
|
||||
[0.272, 0.534, 0.131]
|
||||
])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(600, info.width);
|
||||
@ -87,7 +87,7 @@ describe('Recomb', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('increases the saturation of the image', function (_t, done) {
|
||||
it('increases the saturation of the image', (_t, done) => {
|
||||
const saturationLevel = 1;
|
||||
const output = fixtures.path('output.recomb-saturation.jpg');
|
||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||
@ -108,7 +108,7 @@ describe('Recomb', function () {
|
||||
saturationLevel + 1 - 0.114
|
||||
]
|
||||
])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(600, info.width);
|
||||
@ -122,7 +122,7 @@ describe('Recomb', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('applies opacity 30% to the image', function (_t, done) {
|
||||
it('applies opacity 30% to the image', (_t, done) => {
|
||||
const output = fixtures.path('output.recomb-opacity.png');
|
||||
sharp(fixtures.inputPngWithTransparent)
|
||||
.recomb([
|
||||
@ -131,7 +131,7 @@ describe('Recomb', function () {
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 0.3]
|
||||
])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(48, info.width);
|
||||
@ -145,19 +145,19 @@ describe('Recomb', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid matrix specification', function () {
|
||||
it('missing', function () {
|
||||
assert.throws(function () {
|
||||
describe('invalid matrix specification', () => {
|
||||
it('missing', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).recomb();
|
||||
});
|
||||
});
|
||||
it('incorrect flat data', function () {
|
||||
assert.throws(function () {
|
||||
it('incorrect flat data', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).recomb([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
});
|
||||
});
|
||||
it('incorrect sub size', function () {
|
||||
assert.throws(function () {
|
||||
it('incorrect sub size', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).recomb([
|
||||
[1, 2, 3, 4],
|
||||
[5, 6, 7, 8],
|
||||
@ -165,8 +165,8 @@ describe('Recomb', function () {
|
||||
]);
|
||||
});
|
||||
});
|
||||
it('incorrect top size', function () {
|
||||
assert.throws(function () {
|
||||
it('incorrect top size', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).recomb([[1, 2, 3, 4], [5, 6, 7, 8]]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,15 +9,15 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Resize fit=contain', function () {
|
||||
it('Allows specifying the position as a string', function (_t, done) {
|
||||
describe('Resize fit=contain', () => {
|
||||
it('Allows specifying the position as a string', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240, {
|
||||
fit: 'contain',
|
||||
position: 'center'
|
||||
})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -25,11 +25,11 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG within PNG, no alpha channel', function (_t, done) {
|
||||
it('JPEG within PNG, no alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240, { fit: 'contain' })
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -40,14 +40,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG within WebP, to include alpha channel', function (_t, done) {
|
||||
it('JPEG within WebP, to include alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240, {
|
||||
fit: 'contain',
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.webp()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -58,10 +58,10 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with alpha channel', function (_t, done) {
|
||||
it('PNG with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(50, 50, { fit: 'contain' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -72,10 +72,10 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit PNG with alpha channel', function (_t, done) {
|
||||
it('16-bit PNG with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 16, { fit: 'contain' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -86,13 +86,13 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('16-bit PNG with alpha channel onto RGBA', function (_t, done) {
|
||||
it('16-bit PNG with alpha channel onto RGBA', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 16, {
|
||||
fit: 'contain',
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -103,13 +103,13 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with 2 channels', function (_t, done) {
|
||||
it('PNG with 2 channels', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(32, 16, {
|
||||
fit: 'contain',
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -120,14 +120,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF in LAB colourspace onto RGBA background', function (_t, done) {
|
||||
it('TIFF in LAB colourspace onto RGBA background', (_t, done) => {
|
||||
sharp(fixtures.inputTiffCielab)
|
||||
.resize(64, 128, {
|
||||
fit: 'contain',
|
||||
background: { r: 255, g: 102, b: 0, alpha: 0.5 }
|
||||
})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -138,10 +138,10 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Enlarge', function (_t, done) {
|
||||
it('Enlarge', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.resize(320, 240, { fit: 'contain' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -152,14 +152,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Animated WebP', function () {
|
||||
it('Width only', function (_t, done) {
|
||||
describe('Animated WebP', () => {
|
||||
it('Width only', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(320, 240, {
|
||||
fit: 'contain',
|
||||
background: { r: 255, g: 0, b: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -170,13 +170,13 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Height only', function (_t, done) {
|
||||
it('Height only', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(240, 320, {
|
||||
fit: 'contain',
|
||||
background: { r: 255, g: 0, b: 0 }
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -188,22 +188,22 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid position values should fail', function () {
|
||||
[-1, 8.1, 9, 1000000, false, 'vallejo'].forEach(function (position) {
|
||||
assert.throws(function () {
|
||||
it('Invalid position values should fail', () => {
|
||||
[-1, 8.1, 9, 1000000, false, 'vallejo'].forEach((position) => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'contain', position });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal top', function (_t, done) {
|
||||
it('Position horizontal top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -214,14 +214,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal right top', function (_t, done) {
|
||||
it('Position horizontal right top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -232,14 +232,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal right', function (_t, done) {
|
||||
it('Position horizontal right', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -250,14 +250,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal right bottom', function (_t, done) {
|
||||
it('Position horizontal right bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -268,14 +268,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal bottom', function (_t, done) {
|
||||
it('Position horizontal bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -286,14 +286,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal left bottom', function (_t, done) {
|
||||
it('Position horizontal left bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -304,14 +304,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal left', function (_t, done) {
|
||||
it('Position horizontal left', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -322,14 +322,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal left top', function (_t, done) {
|
||||
it('Position horizontal left top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -340,14 +340,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal north', function (_t, done) {
|
||||
it('Position horizontal north', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.north
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -358,14 +358,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal northeast', function (_t, done) {
|
||||
it('Position horizontal northeast', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.northeast
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -376,14 +376,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal east', function (_t, done) {
|
||||
it('Position horizontal east', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.east
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -394,14 +394,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal southeast', function (_t, done) {
|
||||
it('Position horizontal southeast', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.southeast
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -412,14 +412,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal south', function (_t, done) {
|
||||
it('Position horizontal south', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.south
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -430,14 +430,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal southwest', function (_t, done) {
|
||||
it('Position horizontal southwest', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.southwest
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -448,14 +448,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal west', function (_t, done) {
|
||||
it('Position horizontal west', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.west
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -466,14 +466,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal northwest', function (_t, done) {
|
||||
it('Position horizontal northwest', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.northwest
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -484,14 +484,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position horizontal center', function (_t, done) {
|
||||
it('Position horizontal center', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 100, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.center
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -502,14 +502,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical top', function (_t, done) {
|
||||
it('Position vertical top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -520,14 +520,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical right top', function (_t, done) {
|
||||
it('Position vertical right top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -538,14 +538,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical right', function (_t, done) {
|
||||
it('Position vertical right', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -556,14 +556,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical right bottom', function (_t, done) {
|
||||
it('Position vertical right bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'right bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -574,14 +574,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical bottom', function (_t, done) {
|
||||
it('Position vertical bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -592,14 +592,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical left bottom', function (_t, done) {
|
||||
it('Position vertical left bottom', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left bottom'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -610,14 +610,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical left', function (_t, done) {
|
||||
it('Position vertical left', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -628,14 +628,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical left top', function (_t, done) {
|
||||
it('Position vertical left top', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: 'left top'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -646,14 +646,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical north', function (_t, done) {
|
||||
it('Position vertical north', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.north
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -664,14 +664,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical northeast', function (_t, done) {
|
||||
it('Position vertical northeast', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.northeast
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -682,14 +682,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical east', function (_t, done) {
|
||||
it('Position vertical east', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.east
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -700,14 +700,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical southeast', function (_t, done) {
|
||||
it('Position vertical southeast', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.southeast
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -718,14 +718,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical south', function (_t, done) {
|
||||
it('Position vertical south', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.south
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -736,14 +736,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical southwest', function (_t, done) {
|
||||
it('Position vertical southwest', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.southwest
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -754,14 +754,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical west', function (_t, done) {
|
||||
it('Position vertical west', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.west
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -772,14 +772,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical northwest', function (_t, done) {
|
||||
it('Position vertical northwest', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.northwest
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -790,14 +790,14 @@ describe('Resize fit=contain', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Position vertical center', function (_t, done) {
|
||||
it('Position vertical center', (_t, done) => {
|
||||
sharp(fixtures.inputPngEmbed)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.contain,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
position: sharp.gravity.center
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
|
||||
@ -9,7 +9,7 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Resize fit=cover', function () {
|
||||
describe('Resize fit=cover', () => {
|
||||
[
|
||||
// Position
|
||||
{
|
||||
@ -202,14 +202,14 @@ describe('Resize fit=cover', function () {
|
||||
gravity: sharp.gravity.northwest,
|
||||
fixture: 'gravity-west.jpg'
|
||||
}
|
||||
].forEach(function (settings) {
|
||||
it(settings.name, function (_t, done) {
|
||||
].forEach((settings) => {
|
||||
it(settings.name, (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(settings.width, settings.height, {
|
||||
fit: sharp.fit.cover,
|
||||
position: settings.gravity
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(settings.width, info.width);
|
||||
assert.strictEqual(settings.height, info.height);
|
||||
@ -218,13 +218,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Allows specifying the gravity as a string', function (_t, done) {
|
||||
it('Allows specifying the gravity as a string', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80, 320, {
|
||||
fit: sharp.fit.cover,
|
||||
position: 'east'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(80, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
@ -232,52 +232,48 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid position values fail', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid position values fail', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'cover', position: 9 });
|
||||
}, /Expected valid position\/gravity\/strategy for position but received 9 of type number/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'cover', position: 1.1 });
|
||||
}, /Expected valid position\/gravity\/strategy for position but received 1.1 of type number/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'cover', position: -1 });
|
||||
}, /Expected valid position\/gravity\/strategy for position but received -1 of type number/);
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'cover', position: 'zoinks' }).crop();
|
||||
}, /Expected valid position\/gravity\/strategy for position but received zoinks of type string/);
|
||||
});
|
||||
|
||||
it('Uses default value when none specified', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Uses default value when none specified', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().resize(null, null, { fit: 'cover' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Skip crop when post-resize dimensions are at target', function () {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Skip crop when post-resize dimensions are at target', () => sharp(fixtures.inputJpg)
|
||||
.resize(1600, 1200)
|
||||
.toBuffer()
|
||||
.then(function (input) {
|
||||
return sharp(input)
|
||||
.then((input) => sharp(input)
|
||||
.resize(1110, null, {
|
||||
fit: sharp.fit.cover,
|
||||
position: sharp.strategy.attention
|
||||
})
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (result) {
|
||||
.then((result) => {
|
||||
assert.strictEqual(1110, result.info.width);
|
||||
assert.strictEqual(832, result.info.height);
|
||||
assert.strictEqual(undefined, result.info.cropOffsetLeft);
|
||||
assert.strictEqual(undefined, result.info.cropOffsetTop);
|
||||
});
|
||||
});
|
||||
});
|
||||
})));
|
||||
|
||||
describe('Animated WebP', function () {
|
||||
it('Width only', function (_t, done) {
|
||||
describe('Animated WebP', () => {
|
||||
it('Width only', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(80, 320, { fit: sharp.fit.cover })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(80, info.width);
|
||||
assert.strictEqual(320 * 9, info.height);
|
||||
@ -285,10 +281,10 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Height only', function (_t, done) {
|
||||
it('Height only', (_t, done) => {
|
||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||
.resize(320, 80, { fit: sharp.fit.cover })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(80 * 9, info.height);
|
||||
@ -297,14 +293,14 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Entropy-based strategy', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
describe('Entropy-based strategy', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80, 320, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.entropy
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@ -316,13 +312,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function (_t, done) {
|
||||
it('PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.entropy
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -334,13 +330,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('supports the strategy passed as a string', function (_t, done) {
|
||||
it('supports the strategy passed as a string', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80, {
|
||||
fit: 'cover',
|
||||
position: 'entropy'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -365,14 +361,14 @@ describe('Resize fit=cover', function () {
|
||||
);
|
||||
});
|
||||
|
||||
describe('Attention strategy', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
describe('Attention strategy', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(80, 320, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.attention
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@ -386,13 +382,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG', function (_t, done) {
|
||||
it('PNG', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.attention
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -406,13 +402,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function (_t, done) {
|
||||
it('WebP', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(320, 80, {
|
||||
fit: 'cover',
|
||||
position: sharp.strategy.attention
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(3, info.channels);
|
||||
@ -426,13 +422,13 @@ describe('Resize fit=cover', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('supports the strategy passed as a string', function (_t, done) {
|
||||
it('supports the strategy passed as a string', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 80, {
|
||||
fit: 'cover',
|
||||
position: 'attention'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
|
||||
@ -9,9 +9,9 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Resize dimensions', function () {
|
||||
it('Exact crop', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
||||
describe('Resize dimensions', () => {
|
||||
it('Exact crop', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -21,8 +21,8 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fixed width', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).resize(320).toBuffer(function (err, data, info) {
|
||||
it('Fixed width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).resize(320).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -32,8 +32,8 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Fixed height', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function (err, data, info) {
|
||||
it('Fixed height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -43,8 +43,8 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Identity transform', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).toBuffer(function (err, data, info) {
|
||||
it('Identity transform', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -54,10 +54,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Upscale', function (_t, done) {
|
||||
it('Upscale', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(3000)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -67,26 +67,26 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid width - NaN', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid width - NaN', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize('spoons', 240);
|
||||
}, /Expected positive integer for width but received spoons of type string/);
|
||||
});
|
||||
|
||||
it('Invalid height - NaN', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid height - NaN', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(320, 'spoons');
|
||||
}, /Expected positive integer for height but received spoons of type string/);
|
||||
});
|
||||
|
||||
it('Invalid width - float', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid width - float', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(1.5, 240);
|
||||
}, /Expected positive integer for width but received 1.5 of type number/);
|
||||
});
|
||||
|
||||
it('Invalid height - float', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid height - float', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(320, 1.5);
|
||||
}, /Expected positive integer for height but received 1.5 of type number/);
|
||||
});
|
||||
@ -103,34 +103,34 @@ describe('Resize dimensions', function () {
|
||||
}, /Expected positive integer for height but received 1.5 of type number/);
|
||||
});
|
||||
|
||||
it('Invalid width - too large', function (_t, done) {
|
||||
it('Invalid width - too large', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(0x4000, 1)
|
||||
.webp()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, err instanceof Error);
|
||||
assert.strictEqual('Processed image is too large for the WebP format', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid height - too large', function (_t, done) {
|
||||
it('Invalid height - too large', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(1, 0x4000)
|
||||
.webp()
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, err instanceof Error);
|
||||
assert.strictEqual('Processed image is too large for the WebP format', err.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Webp resize then extract large image', function (_t, done) {
|
||||
it('Webp resize then extract large image', (_t, done) => {
|
||||
sharp(fixtures.inputWebP)
|
||||
.resize(0x4000, 0x4000)
|
||||
.extract({ top: 0x2000, left: 0x2000, width: 256, height: 256 })
|
||||
.webp()
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(256, info.width);
|
||||
@ -139,18 +139,18 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (_t, done) {
|
||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(1080, 607)
|
||||
.webp()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(1080, info.width);
|
||||
assert.strictEqual(607, info.height);
|
||||
sharp(data)
|
||||
.resize(233, 131)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(233, info.width);
|
||||
@ -160,17 +160,17 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', function (_t, done) {
|
||||
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(1920, 1280)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1920, info.width);
|
||||
assert.strictEqual(1280, info.height);
|
||||
sharp(data)
|
||||
.rotate(90)
|
||||
.resize(533, 800)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(533, info.width);
|
||||
assert.strictEqual(800, info.height);
|
||||
@ -179,11 +179,11 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF embed known to cause rounding errors', function (_t, done) {
|
||||
it('TIFF embed known to cause rounding errors', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(240, 320, { fit: sharp.fit.contain })
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -193,11 +193,11 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF known to cause rounding errors', function (_t, done) {
|
||||
it('TIFF known to cause rounding errors', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(240, 320)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -207,11 +207,11 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=inside, portrait', function (_t, done) {
|
||||
it('fit=inside, portrait', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 320, { fit: sharp.fit.inside })
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -221,11 +221,11 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=outside, portrait', function (_t, done) {
|
||||
it('fit=outside, portrait', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 320, { fit: sharp.fit.outside })
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -235,10 +235,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=inside, landscape', function (_t, done) {
|
||||
it('fit=inside, landscape', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 320, { fit: sharp.fit.inside })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -248,10 +248,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=outside, landscape', function (_t, done) {
|
||||
it('fit=outside, landscape', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 320, { fit: sharp.fit.outside })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -261,13 +261,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=inside, provide only one dimension', function (_t, done) {
|
||||
it('fit=inside, provide only one dimension', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 320,
|
||||
fit: sharp.fit.inside
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -277,13 +277,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=outside, provide only one dimension', function (_t, done) {
|
||||
it('fit=outside, provide only one dimension', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 320,
|
||||
fit: sharp.fit.outside
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -293,13 +293,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not enlarge when input width is already less than output width', function (_t, done) {
|
||||
it('Do not enlarge when input width is already less than output width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 2800,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -309,13 +309,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not enlarge when input height is already less than output height', function (_t, done) {
|
||||
it('Do not enlarge when input height is already less than output height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
height: 2300,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -325,14 +325,14 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do crop when fit = cover and withoutEnlargement = true and width >= outputWidth, and height < outputHeight', function (_t, done) {
|
||||
it('Do crop when fit = cover and withoutEnlargement = true and width >= outputWidth, and height < outputHeight', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 3000,
|
||||
height: 1000,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -342,14 +342,14 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do crop when fit = cover and withoutEnlargement = true and width < outputWidth, and height >= outputHeight', function (_t, done) {
|
||||
it('Do crop when fit = cover and withoutEnlargement = true and width < outputWidth, and height >= outputHeight', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 1500,
|
||||
height: 2226,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -359,13 +359,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||
it('Do enlarge when input width is less than output width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 2800,
|
||||
withoutEnlargement: false
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -375,13 +375,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||
it('Do enlarge when input width is less than output width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 2800,
|
||||
withoutReduction: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -391,13 +391,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do enlarge when input height is less than output height', function (_t, done) {
|
||||
it('Do enlarge when input height is less than output height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
height: 2300,
|
||||
withoutReduction: true
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -407,13 +407,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||
it('Do enlarge when input width is less than output width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 2800,
|
||||
withoutReduction: false
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -423,10 +423,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not resize when both withoutEnlargement and withoutReduction are true', function (_t, done) {
|
||||
it('Do not resize when both withoutEnlargement and withoutReduction are true', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 320, { fit: 'fill', withoutEnlargement: true, withoutReduction: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -436,10 +436,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do not reduce size when fit = outside and withoutReduction are true and height > outputHeight and width > outputWidth', function (_t, done) {
|
||||
it('Do not reduce size when fit = outside and withoutReduction are true and height > outputHeight and width > outputWidth', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 320, { fit: 'outside', withoutReduction: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -449,10 +449,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Do resize when fit = outside and withoutReduction are true and input height > height and input width > width ', function (_t, done) {
|
||||
it('Do resize when fit = outside and withoutReduction are true and input height > height and input width > width ', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(3000, 3000, { fit: 'outside', withoutReduction: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -462,10 +462,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, downscale width and height', function (_t, done) {
|
||||
it('fit=fill, downscale width and height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 320, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -475,13 +475,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, downscale width', function (_t, done) {
|
||||
it('fit=fill, downscale width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
width: 320,
|
||||
fit: 'fill'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -491,13 +491,13 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, downscale height', function (_t, done) {
|
||||
it('fit=fill, downscale height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize({
|
||||
height: 320,
|
||||
fit: 'fill'
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -507,10 +507,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, upscale width and height', function (_t, done) {
|
||||
it('fit=fill, upscale width and height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(3000, 3000, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -520,10 +520,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, upscale width', function (_t, done) {
|
||||
it('fit=fill, upscale width', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(3000, null, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -533,10 +533,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, upscale height', function (_t, done) {
|
||||
it('fit=fill, upscale height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(null, 3000, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -546,10 +546,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, downscale width, upscale height', function (_t, done) {
|
||||
it('fit=fill, downscale width, upscale height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 3000, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -559,10 +559,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, upscale width, downscale height', function (_t, done) {
|
||||
it('fit=fill, upscale width, downscale height', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(3000, 320, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -572,10 +572,10 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fit=fill, identity transform', function (_t, done) {
|
||||
it('fit=fill, identity transform', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(null, null, { fit: 'fill' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -585,16 +585,16 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Dimensions that result in differing even shrinks on each axis', function (_t, done) {
|
||||
it('Dimensions that result in differing even shrinks on each axis', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(645, 399)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(645, info.width);
|
||||
assert.strictEqual(399, info.height);
|
||||
sharp(data)
|
||||
.resize(150, 100)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(150, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
@ -603,33 +603,31 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Dimensions that result in differing odd shrinks on each axis', function (_t, done) {
|
||||
return sharp(fixtures.inputJpg)
|
||||
it('Dimensions that result in differing odd shrinks on each axis', (_t, done) => sharp(fixtures.inputJpg)
|
||||
.resize(600, 399)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(600, info.width);
|
||||
assert.strictEqual(399, info.height);
|
||||
sharp(data)
|
||||
.resize(200)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(200, info.width);
|
||||
assert.strictEqual(133, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('resize-diff-shrink-odd.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
[
|
||||
true,
|
||||
false
|
||||
].forEach(function (value) {
|
||||
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (_t, done) {
|
||||
].forEach((value) => {
|
||||
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, (_t, done) => {
|
||||
sharp(fixtures.inputJpgCenteredImage)
|
||||
.resize(9, 8, { fastShrinkOnLoad: value })
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(9, info.width);
|
||||
assert.strictEqual(8, info.height);
|
||||
@ -644,11 +642,11 @@ describe('Resize dimensions', function () {
|
||||
sharp.kernel.mitchell,
|
||||
sharp.kernel.lanczos2,
|
||||
sharp.kernel.lanczos3
|
||||
].forEach(function (kernel) {
|
||||
it(`kernel ${kernel}`, function (_t, done) {
|
||||
].forEach((kernel) => {
|
||||
it(`kernel ${kernel}`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, null, { kernel })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -657,11 +655,11 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('nearest upsampling with integral factor', function (_t, done) {
|
||||
it('nearest upsampling with integral factor', (_t, done) => {
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.resize(210, 210, { kernel: 'nearest' })
|
||||
.png()
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(210, info.width);
|
||||
assert.strictEqual(210, info.height);
|
||||
@ -669,8 +667,7 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Ensure shortest edge (height) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
it('Ensure shortest edge (height) is at least 1 pixel', () => sharp({
|
||||
create: {
|
||||
width: 10,
|
||||
height: 2,
|
||||
@ -680,14 +677,12 @@ describe('Resize dimensions', function () {
|
||||
})
|
||||
.resize(2)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
.then((output) => {
|
||||
assert.strictEqual(2, output.info.width);
|
||||
assert.strictEqual(1, output.info.height);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Ensure shortest edge (width) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
it('Ensure shortest edge (width) is at least 1 pixel', () => sharp({
|
||||
create: {
|
||||
width: 2,
|
||||
height: 10,
|
||||
@ -697,14 +692,12 @@ describe('Resize dimensions', function () {
|
||||
})
|
||||
.resize(null, 2)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
.then((output) => {
|
||||
assert.strictEqual(1, output.info.width);
|
||||
assert.strictEqual(2, output.info.height);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Ensure embedded shortest edge (height) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
it('Ensure embedded shortest edge (height) is at least 1 pixel', () => sharp({
|
||||
create: {
|
||||
width: 200,
|
||||
height: 1,
|
||||
@ -714,14 +707,12 @@ describe('Resize dimensions', function () {
|
||||
})
|
||||
.resize({ width: 50, height: 50, fit: sharp.fit.contain })
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
.then((output) => {
|
||||
assert.strictEqual(50, output.info.width);
|
||||
assert.strictEqual(50, output.info.height);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Ensure embedded shortest edge (width) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
it('Ensure embedded shortest edge (width) is at least 1 pixel', () => sharp({
|
||||
create: {
|
||||
width: 1,
|
||||
height: 200,
|
||||
@ -731,11 +722,10 @@ describe('Resize dimensions', function () {
|
||||
})
|
||||
.resize({ width: 50, height: 50, fit: sharp.fit.contain })
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
.then((output) => {
|
||||
assert.strictEqual(50, output.info.width);
|
||||
assert.strictEqual(50, output.info.height);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Skip shrink-on-load where one dimension <4px', async () => {
|
||||
const jpeg = await sharp({
|
||||
@ -778,20 +768,20 @@ describe('Resize dimensions', function () {
|
||||
assert.strictEqual(height, 334);
|
||||
});
|
||||
|
||||
it('unknown kernel throws', function () {
|
||||
assert.throws(function () {
|
||||
it('unknown kernel throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { kernel: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown fit throws', function () {
|
||||
assert.throws(function () {
|
||||
it('unknown fit throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { fit: 'unknown' });
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown position throws', function () {
|
||||
assert.throws(function () {
|
||||
it('unknown position throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().resize(null, null, { position: 'unknown' });
|
||||
});
|
||||
});
|
||||
@ -799,7 +789,7 @@ describe('Resize dimensions', function () {
|
||||
it('Multiple resize emits warning', () => {
|
||||
let warningMessage = '';
|
||||
const s = sharp();
|
||||
s.on('warning', function (msg) { warningMessage = msg; });
|
||||
s.on('warning', (msg) => { warningMessage = msg; });
|
||||
s.resize(1);
|
||||
assert.strictEqual(warningMessage, '');
|
||||
s.resize(2);
|
||||
|
||||
@ -9,22 +9,22 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Rotation', function () {
|
||||
['autoOrient', 'constructor'].forEach(function (rotateMethod) {
|
||||
describe('Rotation', () => {
|
||||
['autoOrient', 'constructor'].forEach((rotateMethod) => {
|
||||
describe(`Auto orientation via ${rotateMethod}:`, () => {
|
||||
const options = rotateMethod === 'constructor' ? { autoOrient: true } : {};
|
||||
|
||||
['Landscape', 'Portrait'].forEach(function (orientation) {
|
||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
||||
['Landscape', 'Portrait'].forEach((orientation) => {
|
||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach((exifTag) => {
|
||||
const input = fixtures[`inputJpgWith${orientation}Exif${exifTag}`];
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}-out.jpg`);
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, function (_t, done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, (_t, done) => {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
|
||||
const img = sharp(input, options);
|
||||
rotateMethod === 'autoOrient' && img.autoOrient();
|
||||
|
||||
img.toBuffer(function (err, data, info) {
|
||||
img.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(info.width, expectedWidth);
|
||||
assert.strictEqual(info.height, expectedHeight);
|
||||
@ -32,14 +32,14 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, function (_t, done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, (_t, done) => {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [320, 240] : [320, 427];
|
||||
|
||||
const img = sharp(input, options);
|
||||
rotateMethod === 'autoOrient' && img.autoOrient();
|
||||
|
||||
img.resize({ width: 320 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(info.width, expectedWidth);
|
||||
assert.strictEqual(info.height, expectedHeight);
|
||||
@ -48,7 +48,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
if (rotateMethod !== 'constructor') {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, function (_t, done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, (_t, done) => {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape'
|
||||
? (exifTag < 5) ? [320, 240] : [320, 240]
|
||||
: [320, 427];
|
||||
@ -57,7 +57,7 @@ describe('Rotation', function () {
|
||||
.resize({ width: 320 });
|
||||
|
||||
rotateMethod === 'autoOrient' && img.autoOrient();
|
||||
img.toBuffer(function (err, data, info) {
|
||||
img.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(info.width, expectedWidth);
|
||||
assert.strictEqual(info.height, expectedHeight);
|
||||
@ -67,10 +67,10 @@ describe('Rotation', function () {
|
||||
}
|
||||
|
||||
[true, false].forEach((doResize) => {
|
||||
[90, 180, 270, 45].forEach(function (angle) {
|
||||
[90, 180, 270, 45].forEach((angle) => {
|
||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_rotate${angle}-out.jpg`);
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, (_t, done) => {
|
||||
const [width, height] = (angle === 45 ? [742, 742] : [inputWidth, inputHeight]).map((x) => doResize ? Math.floor(x / 1.875) : x);
|
||||
const [expectedWidth, expectedHeight] = angle % 180 === 0 ? [width, height] : [height, width];
|
||||
|
||||
@ -80,7 +80,7 @@ describe('Rotation', function () {
|
||||
img.rotate(angle);
|
||||
doResize && img.resize(expectedWidth);
|
||||
|
||||
img.toBuffer(function (err, data, info) {
|
||||
img.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(info.width, expectedWidth);
|
||||
assert.strictEqual(info.height, expectedHeight);
|
||||
@ -89,11 +89,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
[[true, true], [true, false], [false, true]].forEach(function ([flip, flop]) {
|
||||
[[true, true], [true, false], [false, true]].forEach(([flip, flop]) => {
|
||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
||||
const flipFlopTestName = [flip && 'flip', flop && 'flop'].filter(Boolean).join(' & ');
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, (_t, done) => {
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
||||
|
||||
const img = sharp(input, options);
|
||||
@ -104,7 +104,7 @@ describe('Rotation', function () {
|
||||
flop && img.flop();
|
||||
doResize && img.resize(orientation === 'Landscape' ? 320 : 240);
|
||||
|
||||
img.toBuffer(function (err, data, info) {
|
||||
img.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(info.width, inputWidth / (doResize ? 1.875 : 1));
|
||||
assert.strictEqual(info.height, inputHeight / (doResize ? 1.875 : 1));
|
||||
@ -118,12 +118,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees with semi-transparent background', function (_t, done) {
|
||||
it('Rotate by 30 degrees with semi-transparent background', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.rotate(30, { background: { r: 255, g: 0, b: 0, alpha: 0.5 } })
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(408, info.width);
|
||||
@ -132,11 +132,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees with solid background', function (_t, done) {
|
||||
it('Rotate by 30 degrees with solid background', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.rotate(30, { background: { r: 255, g: 0, b: 0 } })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(408, info.width);
|
||||
@ -145,11 +145,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 90 degrees, respecting output input size', function (_t, done) {
|
||||
it('Rotate by 90 degrees, respecting output input size', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -159,11 +159,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Resize then rotate by 30 degrees, respecting output input size', function (_t, done) {
|
||||
it('Resize then rotate by 30 degrees, respecting output input size', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.rotate(30)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -173,9 +173,9 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
[-3690, -450, -90, 90, 450, 3690].forEach(function (angle) {
|
||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
[-3690, -450, -90, 90, 450, 3690].forEach((angle) => {
|
||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
@ -184,9 +184,9 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) {
|
||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
[-3750, -510, -150, 30, 390, 3630].forEach((angle) => {
|
||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(397, info.width);
|
||||
assert.strictEqual(368, info.height);
|
||||
@ -195,9 +195,9 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
[-3780, -540, 0, 180, 540, 3780].forEach(function (angle) {
|
||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
[-3780, -540, 0, 180, 540, 3780].forEach((angle) => {
|
||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, (_t, done) => {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -206,15 +206,15 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(240, 240, { fit: sharp.fit.fill })
|
||||
.rotate(270)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
@ -223,15 +223,15 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 315 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||
it('Rotate by 315 degrees, square output ignoring aspect ratio', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(240, 240, { fit: sharp.fit.fill })
|
||||
.rotate(315)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(339, info.width);
|
||||
assert.strictEqual(339, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(339, metadata.width);
|
||||
assert.strictEqual(339, metadata.height);
|
||||
@ -240,15 +240,15 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(270)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
@ -257,15 +257,15 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithLandscapeExif8)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
.rotate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, metadata.width);
|
||||
assert.strictEqual(240, metadata.height);
|
||||
@ -274,15 +274,15 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
.rotate(30)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(397, info.width);
|
||||
assert.strictEqual(368, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(397, metadata.width);
|
||||
assert.strictEqual(368, metadata.height);
|
||||
@ -291,17 +291,17 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', function (_t, done) {
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320)
|
||||
.withMetadata()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(427, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(8, metadata.orientation);
|
||||
done();
|
||||
@ -309,11 +309,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (_t, done) {
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -322,17 +322,17 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', function (_t, done) {
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.withMetadata({ orientation: 3 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done);
|
||||
@ -340,17 +340,17 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (_t, done) {
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExifMirroring)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.withMetadata()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done);
|
||||
@ -358,8 +358,8 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate using image that has no EXIF', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) {
|
||||
it('Attempt to auto-rotate using image that has no EXIF', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -369,12 +369,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate image format without EXIF support', function (_t, done) {
|
||||
it('Attempt to auto-rotate image format without EXIF support', (_t, done) => {
|
||||
sharp(fixtures.inputPng)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -384,8 +384,8 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate with a string argument, should fail', function () {
|
||||
assert.throws(function () {
|
||||
it('Rotate with a string argument, should fail', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).rotate('not-a-number');
|
||||
});
|
||||
});
|
||||
@ -436,18 +436,18 @@ describe('Rotation', function () {
|
||||
it('Multiple rotate emits warning', () => {
|
||||
let warningMessage = '';
|
||||
const s = sharp();
|
||||
s.on('warning', function (msg) { warningMessage = msg; });
|
||||
s.on('warning', (msg) => { warningMessage = msg; });
|
||||
s.rotate(90);
|
||||
assert.strictEqual(warningMessage, '');
|
||||
s.rotate(180);
|
||||
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
|
||||
});
|
||||
|
||||
it('Multiple rotate: last one wins (cardinal)', function (_t, done) {
|
||||
it('Multiple rotate: last one wins (cardinal)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(45)
|
||||
.rotate(90)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2225, info.width);
|
||||
assert.strictEqual(2725, info.height);
|
||||
@ -455,11 +455,11 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple rotate: last one wins (non cardinal)', function (_t, done) {
|
||||
it('Multiple rotate: last one wins (non cardinal)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.rotate(45)
|
||||
.toBuffer(function (err, _data, info) {
|
||||
.toBuffer((err, _data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3500, info.width);
|
||||
assert.strictEqual(3500, info.height);
|
||||
@ -467,17 +467,17 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip - vertical', function (_t, done) {
|
||||
it('Flip - vertical', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip()
|
||||
.withMetadata()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done);
|
||||
@ -485,17 +485,17 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flop - horizontal', function (_t, done) {
|
||||
it('Flop - horizontal', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flop()
|
||||
.withMetadata()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
sharp(data).metadata(function (err, metadata) {
|
||||
sharp(data).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1, metadata.orientation);
|
||||
fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done);
|
||||
@ -503,12 +503,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip and flop', function (_t, done) {
|
||||
it('Flip and flop', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip()
|
||||
.flop()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -517,12 +517,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Neither flip nor flop', function (_t, done) {
|
||||
it('Neither flip nor flop', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip(false)
|
||||
.flop(false)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -531,12 +531,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate and flip', function (_t, done) {
|
||||
it('Auto-rotate and flip', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.flip()
|
||||
.resize(320)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -545,12 +545,12 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate and flop', function (_t, done) {
|
||||
it('Auto-rotate and flop', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.flop()
|
||||
.resize(320)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
|
||||
@ -9,12 +9,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Sharpen', function () {
|
||||
it('specific radius 10 (sigma 6)', function (_t, done) {
|
||||
describe('Sharpen', () => {
|
||||
it('specific radius 10 (sigma 6)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(6)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -23,11 +23,11 @@ describe('Sharpen', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (_t, done) {
|
||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(1.5, 0.5, 2.5)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -36,11 +36,11 @@ describe('Sharpen', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', function (_t, done) {
|
||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(3.5, 2, 4)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -66,11 +66,11 @@ describe('Sharpen', function () {
|
||||
});
|
||||
|
||||
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
||||
it('specific radius/levels with alpha channel', function (_t, done) {
|
||||
it('specific radius/levels with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.sharpen(5, 4, 8)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(4, info.channels);
|
||||
@ -81,11 +81,11 @@ describe('Sharpen', function () {
|
||||
});
|
||||
}
|
||||
|
||||
it('mild sharpen', function (_t, done) {
|
||||
it('mild sharpen', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -94,20 +94,20 @@ describe('Sharpen', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid sigma', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid sigma', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).sharpen(-1.5);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid flat', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid flat', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).sharpen(1, -1);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid jagged', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid jagged', () => {
|
||||
assert.throws(() => {
|
||||
sharp(fixtures.inputJpg).sharpen(1, 1, -1);
|
||||
});
|
||||
});
|
||||
@ -142,11 +142,11 @@ describe('Sharpen', function () {
|
||||
/Expected number between 0 and 1000000 for options\.y3 but received -1 of type number/
|
||||
));
|
||||
|
||||
it('sharpened image is larger than non-sharpened', function (_t, done) {
|
||||
it('sharpened image is larger than non-sharpened', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(false)
|
||||
.toBuffer(function (err, notSharpened, info) {
|
||||
.toBuffer((err, notSharpened, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, notSharpened.length > 0);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
@ -155,7 +155,7 @@ describe('Sharpen', function () {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.sharpen(true)
|
||||
.toBuffer(function (err, sharpened, info) {
|
||||
.toBuffer((err, sharpened, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, sharpened.length > 0);
|
||||
assert.strictEqual(true, sharpened.length > notSharpened.length);
|
||||
|
||||
@ -22,9 +22,9 @@ function isInteger (val) {
|
||||
return Number.isInteger(val);
|
||||
}
|
||||
|
||||
describe('Image Stats', function () {
|
||||
it('JPEG', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).stats(function (err, stats) {
|
||||
describe('Image Stats', () => {
|
||||
it('JPEG', (_t, done) => {
|
||||
sharp(fixtures.inputJpg).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -88,8 +88,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG without transparency', function (_t, done) {
|
||||
sharp(fixtures.inputPng).stats(function (err, stats) {
|
||||
it('PNG without transparency', (_t, done) => {
|
||||
sharp(fixtures.inputPng).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -120,8 +120,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with transparency', function (_t, done) {
|
||||
sharp(fixtures.inputPngWithTransparency).stats(function (err, stats) {
|
||||
it('PNG with transparency', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(false, stats.isOpaque);
|
||||
@ -201,8 +201,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG fully transparent', function (_t, done) {
|
||||
sharp(fixtures.inputPngCompleteTransparency).stats(function (err, stats) {
|
||||
it('PNG fully transparent', (_t, done) => {
|
||||
sharp(fixtures.inputPngCompleteTransparency).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(false, stats.isOpaque);
|
||||
@ -234,8 +234,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Tiff', function (_t, done) {
|
||||
sharp(fixtures.inputTiff).stats(function (err, stats) {
|
||||
it('Tiff', (_t, done) => {
|
||||
sharp(fixtures.inputTiff).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -267,8 +267,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function (_t, done) {
|
||||
sharp(fixtures.inputWebP).stats(function (err, stats) {
|
||||
it('WebP', (_t, done) => {
|
||||
sharp(fixtures.inputWebP).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -332,8 +332,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('GIF', function (_t, done) {
|
||||
sharp(fixtures.inputGif).stats(function (err, stats) {
|
||||
it('GIF', (_t, done) => {
|
||||
sharp(fixtures.inputGif).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -397,8 +397,8 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Grayscale GIF with alpha', function (_t, done) {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).stats(function (err, stats) {
|
||||
it('Grayscale GIF with alpha', (_t, done) => {
|
||||
sharp(fixtures.inputGifGreyPlusAlpha).stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(false, stats.isOpaque);
|
||||
@ -479,9 +479,9 @@ describe('Image Stats', function () {
|
||||
assert.strictEqual(sharpness, 0);
|
||||
});
|
||||
|
||||
it('Stream in, Callback out', function (_t, done) {
|
||||
it('Stream in, Callback out', (_t, done) => {
|
||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||
const pipeline = sharp().stats(function (err, stats) {
|
||||
const pipeline = sharp().stats((err, stats) => {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
@ -546,12 +546,12 @@ describe('Image Stats', function () {
|
||||
readable.pipe(pipeline);
|
||||
});
|
||||
|
||||
it('Stream in, Promise out', function () {
|
||||
it('Stream in, Promise out', () => {
|
||||
const pipeline = sharp();
|
||||
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(pipeline);
|
||||
|
||||
return pipeline.stats().then(function (stats) {
|
||||
return pipeline.stats().then((stats) => {
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||
@ -608,13 +608,12 @@ describe('Image Stats', function () {
|
||||
assert.strictEqual(true, isInRange(stats.channels[0].maxX, 0, 2725));
|
||||
assert.strictEqual(true, isInteger(stats.channels[0].maxY));
|
||||
assert.strictEqual(true, isInRange(stats.channels[0].maxY, 0, 2725));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
it('File in, Promise out', function () {
|
||||
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
||||
it('File in, Promise out', () => sharp(fixtures.inputJpg).stats().then((stats) => {
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||
@ -671,10 +670,9 @@ describe('Image Stats', function () {
|
||||
assert.strictEqual(true, isInRange(stats.channels[0].maxX, 0, 2725));
|
||||
assert.strictEqual(true, isInteger(stats.channels[0].maxY));
|
||||
assert.strictEqual(true, isInRange(stats.channels[0].maxY, 0, 2725));
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('Blurred image has lower sharpness than original', () => {
|
||||
const original = sharp(fixtures.inputJpg).stats();
|
||||
@ -688,9 +686,9 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('File input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats(function (err) {
|
||||
.stats((err) => {
|
||||
assert(err.message.includes('Input file has corrupt header'));
|
||||
assert(err.stack.includes('at Sharp.stats'));
|
||||
assert(err.stack.includes(__filename));
|
||||
@ -698,10 +696,10 @@ describe('Image Stats', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Stream input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('Stream input with corrupt header fails gracefully', (_t, done) => {
|
||||
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(
|
||||
sharp()
|
||||
.stats(function (err) {
|
||||
.stats((err) => {
|
||||
assert(err.message.includes('Input buffer has corrupt header'));
|
||||
assert(err.stack.includes('at Sharp.stats'));
|
||||
assert(err.stack.includes(__filename));
|
||||
@ -710,40 +708,38 @@ describe('Image Stats', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('File input with corrupt header fails gracefully, Promise out', function () {
|
||||
return sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats().then(function () {
|
||||
it('File input with corrupt header fails gracefully, Promise out', () => sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.stats().then(() => {
|
||||
throw new Error('Corrupt Header file');
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert.ok(!!err);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('File input with corrupt header fails gracefully, Stream In, Promise Out', function () {
|
||||
it('File input with corrupt header fails gracefully, Stream In, Promise Out', () => {
|
||||
const pipeline = sharp();
|
||||
|
||||
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(pipeline);
|
||||
|
||||
return pipeline
|
||||
.stats().then(function () {
|
||||
.stats().then(() => {
|
||||
throw new Error('Corrupt Header file');
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
assert.ok(!!err);
|
||||
});
|
||||
});
|
||||
|
||||
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||
it('Buffer input with corrupt header fails gracefully', (_t, done) => {
|
||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||
.stats(function (err) {
|
||||
.stats((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Non-existent file in, Promise out', function (_t, done) {
|
||||
sharp('fail').stats().then(function () {
|
||||
it('Non-existent file in, Promise out', (_t, done) => {
|
||||
sharp('fail').stats().then(() => {
|
||||
throw new Error('Non-existent file');
|
||||
}, function (err) {
|
||||
}, (err) => {
|
||||
assert.ok(!!err);
|
||||
done();
|
||||
});
|
||||
|
||||
@ -10,20 +10,20 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('SVG input', function () {
|
||||
it('Convert SVG to PNG at default 72DPI', function (_t, done) {
|
||||
describe('SVG input', () => {
|
||||
it('Convert SVG to PNG at default 72DPI', (_t, done) => {
|
||||
sharp(fixtures.inputSvg)
|
||||
.resize(1024)
|
||||
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
||||
.toFormat('png')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(40, info.width);
|
||||
assert.strictEqual(40, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg72.png'), data, function (err) {
|
||||
fixtures.assertSimilar(fixtures.expected('svg72.png'), data, (err) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, info) {
|
||||
sharp(data).metadata((err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(72, info.density);
|
||||
done();
|
||||
@ -32,19 +32,19 @@ describe('SVG input', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Convert SVG to PNG at 1200DPI', function (_t, done) {
|
||||
it('Convert SVG to PNG at 1200DPI', (_t, done) => {
|
||||
sharp(fixtures.inputSvg, { density: 1200 })
|
||||
.resize(1024)
|
||||
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
||||
.toFormat('png')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(40, info.width);
|
||||
assert.strictEqual(40, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg1200.png'), data, function (err) {
|
||||
fixtures.assertSimilar(fixtures.expected('svg1200.png'), data, (err) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, info) {
|
||||
sharp(data).metadata((err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(1200, info.density);
|
||||
done();
|
||||
@ -53,22 +53,22 @@ describe('SVG input', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Convert SVG to PNG at DPI larger than 2400', function (_t, done) {
|
||||
it('Convert SVG to PNG at DPI larger than 2400', (_t, done) => {
|
||||
const size = 1024;
|
||||
sharp(fixtures.inputSvgSmallViewBox).metadata(function (err, metadata) {
|
||||
sharp(fixtures.inputSvgSmallViewBox).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
const density = (size / Math.max(metadata.width, metadata.height)) * metadata.density;
|
||||
sharp(fixtures.inputSvgSmallViewBox, { density })
|
||||
.resize(size)
|
||||
.toFormat('png')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(size, info.width);
|
||||
assert.strictEqual(size, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('circle.png'), data, function (err) {
|
||||
fixtures.assertSimilar(fixtures.expected('circle.png'), data, (err) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, info) {
|
||||
sharp(data).metadata((err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(9216, info.density);
|
||||
done();
|
||||
@ -78,19 +78,19 @@ describe('SVG input', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Convert SVG to PNG utilizing scale-on-load', function (_t, done) {
|
||||
it('Convert SVG to PNG utilizing scale-on-load', (_t, done) => {
|
||||
const size = 1024;
|
||||
sharp(fixtures.inputSvgSmallViewBox)
|
||||
.resize(size)
|
||||
.toFormat('png')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(size, info.width);
|
||||
assert.strictEqual(size, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('circle.png'), data, function (err) {
|
||||
fixtures.assertSimilar(fixtures.expected('circle.png'), data, (err) => {
|
||||
if (err) throw err;
|
||||
sharp(data).metadata(function (err, info) {
|
||||
sharp(data).metadata((err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(72, info.density);
|
||||
done();
|
||||
@ -99,24 +99,24 @@ describe('SVG input', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Convert SVG to PNG at 14.4DPI', function (_t, done) {
|
||||
it('Convert SVG to PNG at 14.4DPI', (_t, done) => {
|
||||
sharp(fixtures.inputSvg, { density: 14.4 })
|
||||
.toFormat('png')
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(20, info.width);
|
||||
assert.strictEqual(20, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg14.4.png'), data, function (err) {
|
||||
fixtures.assertSimilar(fixtures.expected('svg14.4.png'), data, (err) => {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Convert SVG with embedded images to PNG, respecting dimensions, autoconvert to PNG', function (_t, done) {
|
||||
it('Convert SVG with embedded images to PNG, respecting dimensions, autoconvert to PNG', (_t, done) => {
|
||||
sharp(fixtures.inputSvgWithEmbeddedImages)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(480, info.width);
|
||||
|
||||
@ -10,8 +10,8 @@ const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
const { inRange } = require('../../lib/is');
|
||||
|
||||
describe('Text to image', function () {
|
||||
it('text with default values', async function (t) {
|
||||
describe('Text to image', () => {
|
||||
it('text with default values', async (t) => {
|
||||
const output = fixtures.path('output.text-default.png');
|
||||
const text = sharp({
|
||||
text: {
|
||||
@ -41,7 +41,7 @@ describe('Text to image', function () {
|
||||
assert.ok(info.textAutofitDpi > 0);
|
||||
});
|
||||
|
||||
it('text with width and height', async function (t) {
|
||||
it('text with width and height', async (t) => {
|
||||
const output = fixtures.path('output.text-width-height.png');
|
||||
const text = sharp({
|
||||
text: {
|
||||
@ -61,7 +61,7 @@ describe('Text to image', function () {
|
||||
assert.ok(inRange(info.textAutofitDpi, 900, 1300), `Actual textAutofitDpi ${info.textAutofitDpi}`);
|
||||
});
|
||||
|
||||
it('text with dpi', async function (t) {
|
||||
it('text with dpi', async (t) => {
|
||||
const output = fixtures.path('output.text-dpi.png');
|
||||
const dpi = 300;
|
||||
const text = sharp({
|
||||
@ -79,7 +79,7 @@ describe('Text to image', function () {
|
||||
assert.strictEqual(dpi, metadata.density);
|
||||
});
|
||||
|
||||
it('text with color and pango markup', async function (t) {
|
||||
it('text with color and pango markup', async (t) => {
|
||||
const output = fixtures.path('output.text-color-pango.png');
|
||||
const dpi = 300;
|
||||
const text = sharp({
|
||||
@ -101,7 +101,7 @@ describe('Text to image', function () {
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
});
|
||||
|
||||
it('text with font', async function (t) {
|
||||
it('text with font', async (t) => {
|
||||
const output = fixtures.path('output.text-with-font.png');
|
||||
const text = sharp({
|
||||
text: {
|
||||
@ -119,7 +119,7 @@ describe('Text to image', function () {
|
||||
assert.ok(info.height > 10);
|
||||
});
|
||||
|
||||
it('text with justify and composite', async function (t) {
|
||||
it('text with justify and composite', async (t) => {
|
||||
const output = fixtures.path('output.text-composite.png');
|
||||
const width = 500;
|
||||
const dpi = 300;
|
||||
@ -164,8 +164,8 @@ describe('Text to image', function () {
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
});
|
||||
|
||||
it('bad text input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad text input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
}
|
||||
@ -173,8 +173,8 @@ describe('Text to image', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('fontfile input', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('fontfile input', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -184,8 +184,8 @@ describe('Text to image', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('bad font input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad font input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -195,8 +195,8 @@ describe('Text to image', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('bad fontfile input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad fontfile input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -236,8 +236,8 @@ describe('Text to image', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('bad align input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad align input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -247,8 +247,8 @@ describe('Text to image', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('bad justify input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad justify input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -273,8 +273,8 @@ describe('Text to image', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('bad rgba input', function () {
|
||||
assert.throws(function () {
|
||||
it('bad rgba input', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
@ -299,8 +299,8 @@ describe('Text to image', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('only height or dpi not both', function () {
|
||||
assert.throws(function () {
|
||||
it('only height or dpi not both', () => {
|
||||
assert.throws(() => {
|
||||
sharp({
|
||||
text: {
|
||||
text: 'text',
|
||||
|
||||
@ -9,12 +9,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Threshold', function () {
|
||||
it('threshold 1 jpeg', function (_t, done) {
|
||||
describe('Threshold', () => {
|
||||
it('threshold 1 jpeg', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -23,11 +23,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold 40 jpeg', function (_t, done) {
|
||||
it('threshold 40 jpeg', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(40)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -36,11 +36,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold 128', function (_t, done) {
|
||||
it('threshold 128', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -49,11 +49,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold true (=128)', function (_t, done) {
|
||||
it('threshold true (=128)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(true)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -62,20 +62,20 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold false (=0)', function (_t, done) {
|
||||
it('threshold false (=0)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.threshold(false)
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold grayscale: true (=128)', function (_t, done) {
|
||||
it('threshold grayscale: true (=128)', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128, { grayscale: true })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -84,11 +84,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default jpeg', function (_t, done) {
|
||||
it('threshold default jpeg', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -97,11 +97,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default png transparency', function (_t, done) {
|
||||
it('threshold default png transparency', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -110,11 +110,11 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default png alpha', function (_t, done) {
|
||||
it('threshold default png alpha', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.resize(320, 240)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -123,21 +123,21 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold default webp transparency', function (_t, done) {
|
||||
it('threshold default webp transparency', (_t, done) => {
|
||||
sharp(fixtures.inputWebPWithTransparency)
|
||||
.threshold()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('color threshold', function (_t, done) {
|
||||
it('color threshold', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128, { grayscale: false })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
@ -146,14 +146,14 @@ describe('Threshold', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid threshold -1', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid threshold -1', () => {
|
||||
assert.throws(() => {
|
||||
sharp().threshold(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid threshold 256', function () {
|
||||
assert.throws(function () {
|
||||
it('invalid threshold 256', () => {
|
||||
assert.throws(() => {
|
||||
sharp().threshold(256);
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,13 +12,13 @@ const fixtures = require('../fixtures');
|
||||
|
||||
const outputTiff = fixtures.path('output.tiff');
|
||||
|
||||
describe('TIFF', function () {
|
||||
it('Load TIFF from Buffer', function (_t, done) {
|
||||
describe('TIFF', () => {
|
||||
it('Load TIFF from Buffer', (_t, done) => {
|
||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||
sharp(inputTiffBuffer)
|
||||
.resize(320, 240)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -29,10 +29,10 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Load multi-page TIFF from file', function (_t, done) {
|
||||
it('Load multi-page TIFF from file', (_t, done) => {
|
||||
sharp(fixtures.inputTiffMultipage) // defaults to page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||
.toBuffer((err, defaultData, defaultInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, defaultData.length > 0);
|
||||
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||
@ -40,7 +40,7 @@ describe('TIFF', function () {
|
||||
|
||||
sharp(fixtures.inputTiffMultipage, { page: 1 }) // 50%-scale copy of page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||
.toBuffer((err, scaledData, scaledInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, scaledData.length > 0);
|
||||
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||
@ -52,11 +52,11 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Load multi-page TIFF from Buffer', function (_t, done) {
|
||||
it('Load multi-page TIFF from Buffer', (_t, done) => {
|
||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiffMultipage);
|
||||
sharp(inputTiffBuffer) // defaults to page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||
.toBuffer((err, defaultData, defaultInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, defaultData.length > 0);
|
||||
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||
@ -64,7 +64,7 @@ describe('TIFF', function () {
|
||||
|
||||
sharp(inputTiffBuffer, { page: 1 }) // 50%-scale copy of page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||
.toBuffer((err, scaledData, scaledInfo) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, scaledData.length > 0);
|
||||
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||
@ -76,10 +76,10 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Save TIFF to Buffer', function (_t, done) {
|
||||
it('Save TIFF to Buffer', (_t, done) => {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 240)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
@ -105,19 +105,19 @@ describe('TIFF', function () {
|
||||
)
|
||||
);
|
||||
|
||||
it('Invalid TIFF quality throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF quality throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ quality: 101 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Missing TIFF quality does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Missing TIFF quality does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff();
|
||||
});
|
||||
});
|
||||
|
||||
it('Not squashing TIFF to a bit depth of 1 should not change the file size', function (_t, done) {
|
||||
it('Not squashing TIFF to a bit depth of 1 should not change the file size', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||
@ -134,7 +134,7 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Squashing TIFF to a bit depth of 1 should significantly reduce file size', function (_t, done) {
|
||||
it('Squashing TIFF to a bit depth of 1 should significantly reduce file size', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||
@ -151,8 +151,8 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF bitdepth value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF bitdepth value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ bitdepth: 3 });
|
||||
}, /Error: Expected 1, 2, 4 or 8 for bitdepth but received 3 of type number/);
|
||||
});
|
||||
@ -210,19 +210,19 @@ describe('TIFF', function () {
|
||||
assert.strictEqual(25400, density);
|
||||
});
|
||||
|
||||
it('TIFF invalid xres value should throw an error', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid xres value should throw an error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ xres: '1000.0' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid yres value should throw an error', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid yres value should throw an error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ yres: '1000.0' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF lzw compression with horizontal predictor shrinks test file', function (_t, done) {
|
||||
it('TIFF lzw compression with horizontal predictor shrinks test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -274,7 +274,7 @@ describe('TIFF', function () {
|
||||
})
|
||||
);
|
||||
|
||||
it('TIFF ccittfax4 compression shrinks b-w test file', function (_t, done) {
|
||||
it('TIFF ccittfax4 compression shrinks b-w test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiff).size;
|
||||
sharp(fixtures.inputTiff)
|
||||
.toColourspace('b-w')
|
||||
@ -314,7 +314,7 @@ describe('TIFF', function () {
|
||||
assert.strictEqual(resolutionUnit, 'cm');
|
||||
});
|
||||
|
||||
it('TIFF deflate compression with horizontal predictor shrinks test file', function (_t, done) {
|
||||
it('TIFF deflate compression with horizontal predictor shrinks test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -329,7 +329,7 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression with float predictor shrinks test file', function (_t, done) {
|
||||
it('TIFF deflate compression with float predictor shrinks test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -344,7 +344,7 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression without predictor shrinks test file', function (_t, done) {
|
||||
it('TIFF deflate compression without predictor shrinks test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -359,7 +359,7 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF jpeg compression shrinks test file', function (_t, done) {
|
||||
it('TIFF jpeg compression shrinks test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -373,79 +373,79 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF none compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF none compression does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ compression: 'none' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF lzw compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF lzw compression does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ compression: 'lzw' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF deflate compression does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ compression: 'deflate' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid compression option throws', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid compression option throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ compression: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid compression option throws', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid compression option throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ compression: 'a' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF bigtiff true value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF bigtiff true value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ bigtiff: true });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF bigtiff value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF bigtiff value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ bigtiff: 'true' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid predictor option throws', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid predictor option throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ predictor: 'a' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid resolutionUnit option throws', function () {
|
||||
assert.throws(function () {
|
||||
it('TIFF invalid resolutionUnit option throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ resolutionUnit: 'none' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF horizontal predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF horizontal predictor does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ predictor: 'horizontal' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF float predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF float predictor does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ predictor: 'float' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF none predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF none predictor does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ predictor: 'none' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF tiled pyramid image without compression enlarges test file', function (_t, done) {
|
||||
it('TIFF tiled pyramid image without compression enlarges test file', (_t, done) => {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
@ -463,89 +463,89 @@ describe('TIFF', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF pyramid true value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF pyramid true value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ pyramid: true });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF pyramid value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF pyramid value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ pyramid: 'true' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF miniswhite true value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF miniswhite true value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ miniswhite: true });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF miniswhite value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF miniswhite value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ miniswhite: 'true' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF tile value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF tile value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ tile: 'true' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF tile true value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('TIFF tile true value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ tile: true });
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid TIFF tileHeight value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid TIFF tileHeight value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ tileHeight: 512 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid TIFF tileWidth value does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid TIFF tileWidth value does not throw error', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tiff({ tileWidth: 512 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF tileHeight value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF tileHeight value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ tileHeight: '256' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF tileWidth value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF tileWidth value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ tileWidth: '256' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF tileHeight value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF tileHeight value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ tileHeight: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF tileWidth value throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid TIFF tileWidth value throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tiff({ tileWidth: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF file input with invalid page fails gracefully', function (_t, done) {
|
||||
it('TIFF file input with invalid page fails gracefully', (_t, done) => {
|
||||
sharp(fixtures.inputTiffMultipage, { page: 2 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF buffer input with invalid page fails gracefully', function (_t, done) {
|
||||
it('TIFF buffer input with invalid page fails gracefully', (_t, done) => {
|
||||
sharp(fs.readFileSync(fixtures.inputTiffMultipage), { page: 2 })
|
||||
.toBuffer(function (err) {
|
||||
.toBuffer((err) => {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
|
||||
@ -14,27 +14,26 @@ const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
// Verifies all tiles in a given dz output directory are <= size
|
||||
const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, done) {
|
||||
const assertDeepZoomTiles = (directory, expectedSize, expectedLevels, done) => {
|
||||
// Get levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
||||
assert.strictEqual(expectedLevels, levels.length);
|
||||
// Get tiles
|
||||
const tiles = [];
|
||||
levels.forEach(function (level) {
|
||||
levels.forEach((level) => {
|
||||
// Verify level directory name
|
||||
assert.strictEqual(true, /^[0-9]+$/.test(level));
|
||||
fs.readdirSync(path.join(directory, level)).forEach(function (tile) {
|
||||
fs.readdirSync(path.join(directory, level)).forEach((tile) => {
|
||||
// Verify tile file name
|
||||
assert.strictEqual(true, /^[0-9]+_[0-9]+\.jpeg$/.test(tile));
|
||||
tiles.push(path.join(directory, level, tile));
|
||||
});
|
||||
});
|
||||
// Verify each tile is <= expectedSize
|
||||
Promise.all(tiles.map(function (tile) {
|
||||
return sharp(tile)
|
||||
Promise.all(tiles.map((tile) => sharp(tile)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
@ -42,20 +41,19 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(true, metadata.width <= expectedSize);
|
||||
assert.strictEqual(true, metadata.height <= expectedSize);
|
||||
});
|
||||
}))
|
||||
})))
|
||||
.then(() => done())
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const assertZoomifyTiles = function (directory, expectedLevels, done) {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
const assertZoomifyTiles = (directory, expectedLevels, done) => {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.ok(stat.isFile());
|
||||
assert.ok(stat.size > 0);
|
||||
|
||||
let maxTileLevel = -1;
|
||||
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach(function (tile) {
|
||||
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach((tile) => {
|
||||
// Verify tile file name
|
||||
assert.ok(/^[0-9]+-[0-9]+-[0-9]+\.jpg$/.test(tile));
|
||||
const level = Number(tile.split('-')[0]);
|
||||
@ -68,24 +66,24 @@ const assertZoomifyTiles = function (directory, expectedLevels, done) {
|
||||
});
|
||||
};
|
||||
|
||||
const assertGoogleTiles = function (directory, expectedLevels, done) {
|
||||
const assertGoogleTiles = (directory, expectedLevels, done) => {
|
||||
// Get levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
||||
assert.strictEqual(expectedLevels, levels.length);
|
||||
|
||||
fs.stat(path.join(directory, 'blank.png'), function (err, stat) {
|
||||
fs.stat(path.join(directory, 'blank.png'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.ok(stat.isFile());
|
||||
assert.ok(stat.size > 0);
|
||||
|
||||
// Basic check to confirm lowest and highest level tiles exist
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
|
||||
fs.stat(path.join(directory, (expectedLevels - 1).toString(), '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, (expectedLevels - 1).toString(), '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -96,7 +94,7 @@ const assertGoogleTiles = function (directory, expectedLevels, done) {
|
||||
};
|
||||
|
||||
// Verifies tiles at specified level in a given output directory are > size+overlap
|
||||
const assertTileOverlap = function (directory, tileSize, done) {
|
||||
const assertTileOverlap = (directory, tileSize, done) => {
|
||||
// Get sorted levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name).sort((a, b) => a - b);
|
||||
@ -107,7 +105,7 @@ const assertTileOverlap = function (directory, tileSize, done) {
|
||||
// Select a tile from the approximate center of the image
|
||||
const squareTile = path.join(directory, highestLevel, tiles[Math.floor(tiles.length / 2)]);
|
||||
|
||||
sharp(squareTile).metadata(function (err, metadata) {
|
||||
sharp(squareTile).metadata((err, metadata) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -119,10 +117,10 @@ const assertTileOverlap = function (directory, tileSize, done) {
|
||||
});
|
||||
};
|
||||
|
||||
describe('Tile', function () {
|
||||
it('Valid size values pass', function () {
|
||||
[1, 8192].forEach(function (size) {
|
||||
assert.doesNotThrow(function () {
|
||||
describe('Tile', () => {
|
||||
it('Valid size values pass', () => {
|
||||
[1, 8192].forEach((size) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
size
|
||||
});
|
||||
@ -130,9 +128,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid size values fail', function () {
|
||||
['zoinks', 1.1, -1, 0, 8193].forEach(function (size) {
|
||||
assert.throws(function () {
|
||||
it('Invalid size values fail', () => {
|
||||
['zoinks', 1.1, -1, 0, 8193].forEach((size) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
size
|
||||
});
|
||||
@ -140,9 +138,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid overlap values pass', function () {
|
||||
[0, 8192].forEach(function (overlap) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid overlap values pass', () => {
|
||||
[0, 8192].forEach((overlap) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
size: 8192,
|
||||
overlap
|
||||
@ -151,9 +149,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid overlap values fail', function () {
|
||||
['zoinks', 1.1, -1, 8193].forEach(function (overlap) {
|
||||
assert.throws(function () {
|
||||
it('Invalid overlap values fail', () => {
|
||||
['zoinks', 1.1, -1, 8193].forEach((overlap) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
overlap
|
||||
});
|
||||
@ -161,9 +159,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid container values pass', function () {
|
||||
['fs', 'zip'].forEach(function (container) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid container values pass', () => {
|
||||
['fs', 'zip'].forEach((container) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
container
|
||||
});
|
||||
@ -171,9 +169,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid container values fail', function () {
|
||||
['zoinks', 1].forEach(function (container) {
|
||||
assert.throws(function () {
|
||||
it('Invalid container values fail', () => {
|
||||
['zoinks', 1].forEach((container) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
container
|
||||
});
|
||||
@ -181,9 +179,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid layout values pass', function () {
|
||||
['dz', 'google', 'zoomify'].forEach(function (layout) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid layout values pass', () => {
|
||||
['dz', 'google', 'zoomify'].forEach((layout) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
layout
|
||||
});
|
||||
@ -191,9 +189,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid layout values fail', function () {
|
||||
['zoinks', 1].forEach(function (layout) {
|
||||
assert.throws(function () {
|
||||
it('Invalid layout values fail', () => {
|
||||
['zoinks', 1].forEach((layout) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
layout
|
||||
});
|
||||
@ -201,30 +199,30 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid formats pass', function () {
|
||||
['jpeg', 'png', 'webp'].forEach(function (format) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid formats pass', () => {
|
||||
['jpeg', 'png', 'webp'].forEach((format) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().toFormat(format).tile();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid formats fail', function () {
|
||||
['tiff', 'raw'].forEach(function (format) {
|
||||
assert.throws(function () {
|
||||
it('Invalid formats fail', () => {
|
||||
['tiff', 'raw'].forEach((format) => {
|
||||
assert.throws(() => {
|
||||
sharp().toFormat(format).tile();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid depths pass', function () {
|
||||
['onepixel', 'onetile', 'one'].forEach(function (depth) {
|
||||
it('Valid depths pass', () => {
|
||||
['onepixel', 'onetile', 'one'].forEach((depth) => {
|
||||
assert.doesNotThrow(() => sharp().tile({ depth }));
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid depths fail', function () {
|
||||
['depth', 1].forEach(function (depth) {
|
||||
it('Invalid depths fail', () => {
|
||||
['depth', 1].forEach((depth) => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ depth }),
|
||||
/Expected one of: onepixel, onetile, one for depth but received/
|
||||
@ -232,16 +230,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Prevent larger overlap than default size', function () {
|
||||
assert.throws(function () {
|
||||
it('Prevent larger overlap than default size', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
overlap: 257
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Prevent larger overlap than provided size', function () {
|
||||
assert.throws(function () {
|
||||
it('Prevent larger overlap than provided size', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
size: 512,
|
||||
overlap: 513
|
||||
@ -249,9 +247,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid rotation angle values pass', function () {
|
||||
[90, 270, -90].forEach(function (angle) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid rotation angle values pass', () => {
|
||||
[90, 270, -90].forEach((angle) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
angle
|
||||
});
|
||||
@ -259,9 +257,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid rotation angle values fail', function () {
|
||||
['zoinks', 1.1, -1, 27].forEach(function (angle) {
|
||||
assert.throws(function () {
|
||||
it('Invalid rotation angle values fail', () => {
|
||||
['zoinks', 1.1, -1, 27].forEach((angle) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
angle
|
||||
});
|
||||
@ -269,9 +267,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid skipBlanks threshold values pass', function () {
|
||||
[-1, 0, 255, 65535].forEach(function (skipBlanksThreshold) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid skipBlanks threshold values pass', () => {
|
||||
[-1, 0, 255, 65535].forEach((skipBlanksThreshold) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
skipBlanks: skipBlanksThreshold
|
||||
});
|
||||
@ -279,9 +277,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('InvalidskipBlanks threshold values fail', function () {
|
||||
['zoinks', -2, 65536].forEach(function (skipBlanksThreshold) {
|
||||
assert.throws(function () {
|
||||
it('InvalidskipBlanks threshold values fail', () => {
|
||||
['zoinks', -2, 65536].forEach((skipBlanksThreshold) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
skipBlanks: skipBlanksThreshold
|
||||
});
|
||||
@ -289,42 +287,42 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid center parameter value passes', function () {
|
||||
it('Valid center parameter value passes', () => {
|
||||
assert.doesNotThrow(
|
||||
() => sharp().tile({ center: true })
|
||||
);
|
||||
});
|
||||
|
||||
it('Invalid centre parameter value fails', function () {
|
||||
it('Invalid centre parameter value fails', () => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ centre: 'true' }),
|
||||
/Expected boolean for tileCentre but received true of type string/
|
||||
);
|
||||
});
|
||||
|
||||
it('Valid id parameter value passes', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid id parameter value passes', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
id: 'test'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid id parameter value fails', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid id parameter value fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
id: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid basename parameter value passes', function () {
|
||||
it('Valid basename parameter value passes', () => {
|
||||
assert.doesNotThrow(
|
||||
() => sharp().tile({ basename: 'pass' })
|
||||
);
|
||||
});
|
||||
|
||||
it('Invalid basename parameter value fails', function () {
|
||||
it('Invalid basename parameter value fails', () => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ basename: true }),
|
||||
/Expected string for basename but received/
|
||||
@ -332,11 +330,11 @@ describe('Tile', function () {
|
||||
});
|
||||
|
||||
if (sharp.format.dz.output.file) {
|
||||
it('Deep Zoom layout', function (_t, done) {
|
||||
it('Deep Zoom layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFile(fixtures.path('output.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -348,37 +346,37 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with custom size+overlap', function (_t, done) {
|
||||
it('Deep Zoom layout with custom size+overlap', (_t, done) => {
|
||||
const directory = fixtures.path('output.512.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
overlap: 16
|
||||
})
|
||||
.toFile(fixtures.path('output.512.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('undefined', typeof info.size);
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, function () {
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, () => {
|
||||
assertTileOverlap(directory, 512, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with custom size+angle', function (_t, done) {
|
||||
it('Deep Zoom layout with custom size+angle', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_90.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
angle: 90
|
||||
})
|
||||
.toFile(fixtures.path('output.512_90.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512_90.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -392,7 +390,7 @@ describe('Tile', function () {
|
||||
// expected are w=512 and h=170 for the 0_1.jpeg.
|
||||
// if a 0 angle is supplied to the .tile function
|
||||
// the expected values are w=170 and h=512 for the 1_0.jpeg
|
||||
sharp(tile).metadata(function (err, metadata) {
|
||||
sharp(tile).metadata((err, metadata) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@ -404,15 +402,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of one', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of one', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_depth_one.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
depth: 'one'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 1, done);
|
||||
@ -420,15 +418,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of onepixel', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of onepixel', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_depth_onepixel.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
depth: 'onepixel'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 13, done);
|
||||
@ -436,15 +434,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of onetile', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.256_depth_onetile.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
depth: 'onetile'
|
||||
})
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 256, 5, done);
|
||||
@ -452,15 +450,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with skipBlanks', function (_t, done) {
|
||||
it('Deep Zoom layout with skipBlanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.256_skip_blanks.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpgOverlayLayer2)
|
||||
.tile({
|
||||
size: 256,
|
||||
skipBlanks: 0
|
||||
})
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// assert them 0_0.jpeg doesn't exist because it's a white tile
|
||||
const whiteTilePath = path.join(directory, '11', '0_0.jpeg');
|
||||
@ -471,21 +469,21 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout', function (_t, done) {
|
||||
it('Zoomify layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'zoomify'
|
||||
})
|
||||
.toFile(fixtures.path('output.zoomify.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.zoomify.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -495,16 +493,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth one', function (_t, done) {
|
||||
it('Zoomify layout with depth one', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_one.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'one'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -516,16 +514,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth onetile', function (_t, done) {
|
||||
it('Zoomify layout with depth onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_onetile.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'onetile'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -537,16 +535,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth onepixel', function (_t, done) {
|
||||
it('Zoomify layout with depth onepixel', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_onepixel.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'onepixel'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -558,16 +556,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with skip blanks', function (_t, done) {
|
||||
it('Zoomify layout with skip blanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.skipBlanks.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpgOverlayLayer2)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
skipBlanks: 0
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
// assert them 0_0.jpeg doesn't exist because it's a white tile
|
||||
const whiteTilePath = path.join(directory, 'TileGroup0', '2-0-0.jpg');
|
||||
@ -582,21 +580,21 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout', function (_t, done) {
|
||||
it('Google layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -606,9 +604,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with jpeg format', function (_t, done) {
|
||||
it('Google layout with jpeg format', (_t, done) => {
|
||||
const directory = fixtures.path('output.jpg.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.jpeg({
|
||||
quality: 1
|
||||
@ -616,7 +614,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -624,7 +622,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.jpg');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@ -633,7 +631,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size < 2000);
|
||||
done();
|
||||
@ -643,9 +641,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with png format', function (_t, done) {
|
||||
it('Google layout with png format', (_t, done) => {
|
||||
const directory = fixtures.path('output.png.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.png({
|
||||
compressionLevel: 0
|
||||
@ -653,7 +651,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -661,7 +659,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.png');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@ -670,7 +668,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size > 44000);
|
||||
done();
|
||||
@ -680,9 +678,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with webp format', function (_t, done) {
|
||||
it('Google layout with webp format', (_t, done) => {
|
||||
const directory = fixtures.path('output.webp.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.webp({
|
||||
quality: 1,
|
||||
@ -691,7 +689,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -699,7 +697,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.webp');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@ -708,7 +706,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size < 2000);
|
||||
done();
|
||||
@ -718,16 +716,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with depth one', function (_t, done) {
|
||||
it('Google layout with depth one', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_one.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
depth: 'one',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -739,16 +737,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with depth onetile', function (_t, done) {
|
||||
it('Google layout with depth onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_onetile.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
depth: 'onetile',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -760,15 +758,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with default skip Blanks', function (_t, done) {
|
||||
it('Google layout with default skip Blanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_skipBlanks.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputPng)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
|
||||
const whiteTilePath = path.join(directory, '4', '8', '0.jpg');
|
||||
@ -784,15 +782,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with center image in tile', function (_t, done) {
|
||||
it('Google layout with center image in tile', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_center.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
center: true,
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -804,15 +802,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with center image in tile centre', function (_t, done) {
|
||||
it('Google layout with center image in tile centre', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_center.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
centre: true,
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -824,17 +822,17 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('IIIFv2 layout', function (_t, done) {
|
||||
it('IIIFv2 layout', (_t, done) => {
|
||||
const name = 'output.iiif.info';
|
||||
const directory = fixtures.path(name);
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
const id = 'https://sharp.test.com/iiif';
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'iiif',
|
||||
id
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -844,7 +842,7 @@ describe('Tile', function () {
|
||||
const infoJson = require(path.join(directory, 'info.json'));
|
||||
assert.strictEqual('http://iiif.io/api/image/2/context.json', infoJson['@context']);
|
||||
assert.strictEqual(`${id}/${name}`, infoJson['@id']);
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,', '0', 'default.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,', '0', 'default.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -854,17 +852,17 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('IIIFv3 layout', function (_t, done) {
|
||||
it('IIIFv3 layout', (_t, done) => {
|
||||
const name = 'output.iiif3.info';
|
||||
const directory = fixtures.path(name);
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
const id = 'https://sharp.test.com/iiif3';
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'iiif3',
|
||||
id
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -875,7 +873,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual('http://iiif.io/api/image/3/context.json', infoJson['@context']);
|
||||
assert.strictEqual('ImageService3', infoJson.type);
|
||||
assert.strictEqual(`${id}/${name}`, infoJson.id);
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,256', '0', 'default.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,256', '0', 'default.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -885,20 +883,20 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using file extension', function (_t, done) {
|
||||
it('Write to ZIP container using file extension', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.container.zip');
|
||||
const extractTo = fixtures.path('output.dz.container');
|
||||
const directory = path.join(extractTo, 'output.dz.container_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFile(container, function (err, info) {
|
||||
.toFile(container, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
fs.stat(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -912,16 +910,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using container tile option', function (_t, done) {
|
||||
it('Write to ZIP container using container tile option', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.containeropt.zip');
|
||||
const extractTo = fixtures.path('output.dz.containeropt');
|
||||
const directory = path.join(extractTo, 'output.dz.containeropt_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
container: 'zip'
|
||||
})
|
||||
.toFile(container, function (err, info) {
|
||||
.toFile(container, (err, info) => {
|
||||
// Vips overrides .dzi extension to .zip used by container var below
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
@ -929,7 +927,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
fs.stat(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@ -943,14 +941,14 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write ZIP container to Buffer', function (_t, done) {
|
||||
it('Write ZIP container to Buffer', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.tiles.zip');
|
||||
const extractTo = fixtures.path('output.dz.tiles');
|
||||
const directory = path.join(extractTo, 'output.dz.tiles_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({ basename: 'output.dz.tiles' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@ -958,7 +956,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
fs.writeFileSync(container, data);
|
||||
fs.stat(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
|
||||
@ -9,7 +9,7 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Timeout', function () {
|
||||
describe('Timeout', () => {
|
||||
it('Will timeout after 1s when performing slow blur operation', () => assert.rejects(
|
||||
() => sharp(fixtures.inputJpg)
|
||||
.blur(200)
|
||||
|
||||
@ -12,13 +12,13 @@ const fixtures = require('../fixtures');
|
||||
// Allow for small rounding differences between platforms
|
||||
const maxDistance = 6;
|
||||
|
||||
describe('Tint', function () {
|
||||
it('tints rgb image red', function (_t, done) {
|
||||
describe('Tint', () => {
|
||||
it('tints rgb image red', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-red.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.tint('#FF0000')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-red.jpg'), maxDistance);
|
||||
@ -26,12 +26,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints rgb image green', function (_t, done) {
|
||||
it('tints rgb image green', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-green.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.tint('#00FF00')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-green.jpg'), maxDistance);
|
||||
@ -39,12 +39,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints rgb image blue', function (_t, done) {
|
||||
it('tints rgb image blue', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-blue.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.tint('#0000FF')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-blue.jpg'), maxDistance);
|
||||
@ -52,12 +52,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints rgb image with sepia tone', function (_t, done) {
|
||||
it('tints rgb image with sepia tone', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-sepia-hex.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.tint('#704214')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -66,12 +66,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints rgb image with sepia tone with rgb colour', function (_t, done) {
|
||||
it('tints rgb image with sepia tone with rgb colour', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-sepia-rgb.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.tint([112, 66, 20])
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -80,12 +80,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints rgb image with alpha channel', function (_t, done) {
|
||||
it('tints rgb image with alpha channel', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-alpha.png');
|
||||
sharp(fixtures.inputPngRGBWithAlpha)
|
||||
.resize(320, 240)
|
||||
.tint('#704214')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
@ -94,12 +94,12 @@ describe('Tint', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('tints cmyk image red', function (_t, done) {
|
||||
it('tints cmyk image red', (_t, done) => {
|
||||
const output = fixtures.path('output.tint-cmyk.jpg');
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
.resize(320, 240)
|
||||
.tint('#FF0000')
|
||||
.toFile(output, function (err, info) {
|
||||
.toFile(output, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-cmyk.jpg'), maxDistance);
|
||||
|
||||
@ -10,8 +10,8 @@ const sharp = require('../../');
|
||||
const inRange = require('../../lib/is').inRange;
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Trim borders', function () {
|
||||
it('Skip shrink-on-load', function (_t, done) {
|
||||
describe('Trim borders', () => {
|
||||
it('Skip shrink-on-load', (_t, done) => {
|
||||
const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg');
|
||||
sharp(fixtures.inputJpgOverlayLayer2)
|
||||
.trim()
|
||||
@ -19,7 +19,7 @@ describe('Trim borders', function () {
|
||||
width: 300,
|
||||
fastShrinkOnLoad: false
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(300, info.width);
|
||||
@ -44,13 +44,13 @@ describe('Trim borders', function () {
|
||||
})
|
||||
);
|
||||
|
||||
it('16-bit PNG with alpha channel', function (_t, done) {
|
||||
it('16-bit PNG with alpha channel', (_t, done) => {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 32)
|
||||
.trim({
|
||||
threshold: 20
|
||||
})
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
@ -63,7 +63,7 @@ describe('Trim borders', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to trim 2x2 pixel image fails', function (_t, done) {
|
||||
it('Attempt to trim 2x2 pixel image fails', (_t, done) => {
|
||||
sharp({
|
||||
create: {
|
||||
width: 2,
|
||||
@ -211,7 +211,7 @@ describe('Trim borders', function () {
|
||||
assert.strictEqual(info.trimOffsetTop, -552);
|
||||
});
|
||||
|
||||
describe('Invalid parameters', function () {
|
||||
describe('Invalid parameters', () => {
|
||||
Object.entries({
|
||||
'Invalid string': 'fail',
|
||||
'Invalid background option': {
|
||||
@ -223,16 +223,16 @@ describe('Trim borders', function () {
|
||||
'Invalid lineArt': {
|
||||
lineArt: 'fail'
|
||||
}
|
||||
}).forEach(function ([description, parameter]) {
|
||||
it(description, function () {
|
||||
assert.throws(function () {
|
||||
}).forEach(([description, parameter]) => {
|
||||
it(description, () => {
|
||||
assert.throws(() => {
|
||||
sharp().trim(parameter);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Specific background colour', function () {
|
||||
describe('Specific background colour', () => {
|
||||
it('Doesn\'t trim at all', async () => {
|
||||
const { info } = await sharp(fixtures.inputPngTrimSpecificColour)
|
||||
.trim({
|
||||
|
||||
@ -7,24 +7,24 @@ const { describe, it } = require('node:test');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Unflatten', function () {
|
||||
it('unflatten white background', function (_t, done) {
|
||||
describe('Unflatten', () => {
|
||||
it('unflatten white background', (_t, done) => {
|
||||
sharp(fixtures.inputPng).unflatten()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('unflatten-white-transparent.png'), data, { threshold: 0 }, done);
|
||||
});
|
||||
});
|
||||
it('unflatten transparent image', function (_t, done) {
|
||||
it('unflatten transparent image', (_t, done) => {
|
||||
sharp(fixtures.inputPngTrimSpecificColourIncludeAlpha).unflatten()
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('unflatten-flag-white-transparent.png'), data, { threshold: 0 }, done);
|
||||
});
|
||||
});
|
||||
it('unflatten using threshold', function (_t, done) {
|
||||
it('unflatten using threshold', (_t, done) => {
|
||||
sharp(fixtures.inputPngPalette).unflatten().threshold(128, { grayscale: false })
|
||||
.toBuffer(function (err, data) {
|
||||
.toBuffer((err, data) => {
|
||||
if (err) throw err;
|
||||
fixtures.assertSimilar(fixtures.expected('unflatten-swiss.png'), data, { threshold: 1 }, done);
|
||||
});
|
||||
|
||||
@ -8,9 +8,9 @@ const assert = require('node:assert');
|
||||
const semver = require('semver');
|
||||
const sharp = require('../../');
|
||||
|
||||
describe('Utilities', function () {
|
||||
describe('Cache', function () {
|
||||
it('Can be disabled', function (_t, done) {
|
||||
describe('Utilities', () => {
|
||||
describe('Cache', () => {
|
||||
it('Can be disabled', (_t, done) => {
|
||||
const check = setInterval(() => {
|
||||
const cache = sharp.cache(false);
|
||||
const empty =
|
||||
@ -26,13 +26,13 @@ describe('Utilities', function () {
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
it('Can be enabled with defaults', function () {
|
||||
it('Can be enabled with defaults', () => {
|
||||
const cache = sharp.cache(true);
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
assert.strictEqual(cache.files.max, 20);
|
||||
assert.strictEqual(cache.items.max, 100);
|
||||
});
|
||||
it('Can be set to zero', function () {
|
||||
it('Can be set to zero', () => {
|
||||
const cache = sharp.cache({
|
||||
memory: 0,
|
||||
files: 0,
|
||||
@ -42,7 +42,7 @@ describe('Utilities', function () {
|
||||
assert.strictEqual(cache.files.max, 0);
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function () {
|
||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', () => {
|
||||
const cache = sharp.cache({
|
||||
memory: 10,
|
||||
files: 100,
|
||||
@ -52,7 +52,7 @@ describe('Utilities', function () {
|
||||
assert.strictEqual(cache.files.max, 100);
|
||||
assert.strictEqual(cache.items.max, 1000);
|
||||
});
|
||||
it('Ignores invalid values', function () {
|
||||
it('Ignores invalid values', () => {
|
||||
sharp.cache(true);
|
||||
const cache = sharp.cache('spoons');
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
@ -61,23 +61,23 @@ describe('Utilities', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Concurrency', function () {
|
||||
it('Can be set to use 16 threads', function () {
|
||||
describe('Concurrency', () => {
|
||||
it('Can be set to use 16 threads', () => {
|
||||
sharp.concurrency(16);
|
||||
assert.strictEqual(16, sharp.concurrency());
|
||||
});
|
||||
it('Can be reset to default', function () {
|
||||
it('Can be reset to default', () => {
|
||||
sharp.concurrency(0);
|
||||
assert.strictEqual(true, sharp.concurrency() > 0);
|
||||
});
|
||||
it('Ignores invalid values', function () {
|
||||
it('Ignores invalid values', () => {
|
||||
const defaultConcurrency = sharp.concurrency();
|
||||
sharp.concurrency('spoons');
|
||||
assert.strictEqual(defaultConcurrency, sharp.concurrency());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Counters', function () {
|
||||
describe('Counters', () => {
|
||||
it('Have zero value at rest', (_t, done) => {
|
||||
queueMicrotask(() => {
|
||||
const counters = sharp.counters();
|
||||
@ -88,28 +88,28 @@ describe('Utilities', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('SIMD', function () {
|
||||
it('Can get current state', function () {
|
||||
describe('SIMD', () => {
|
||||
it('Can get current state', () => {
|
||||
const simd = sharp.simd();
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
it('Can disable', function () {
|
||||
it('Can disable', () => {
|
||||
const simd = sharp.simd(false);
|
||||
assert.strictEqual(simd, false);
|
||||
});
|
||||
it('Can attempt to enable', function () {
|
||||
it('Can attempt to enable', () => {
|
||||
const simd = sharp.simd(true);
|
||||
assert.strictEqual(typeof simd, 'boolean');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Format', function () {
|
||||
it('Contains expected attributes', function () {
|
||||
describe('Format', () => {
|
||||
it('Contains expected attributes', () => {
|
||||
assert.strictEqual('object', typeof sharp.format);
|
||||
Object.keys(sharp.format).forEach(function (format) {
|
||||
Object.keys(sharp.format).forEach((format) => {
|
||||
assert.strictEqual(true, 'id' in sharp.format[format]);
|
||||
assert.strictEqual(format, sharp.format[format].id);
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
['input', 'output'].forEach((direction) => {
|
||||
assert.strictEqual(true, direction in sharp.format[format]);
|
||||
assert.strictEqual('object', typeof sharp.format[format][direction]);
|
||||
assert.strictEqual(true, [3, 4].includes(Object.keys(sharp.format[format][direction]).length));
|
||||
@ -122,30 +122,30 @@ describe('Utilities', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('Raw file=false, buffer=true, stream=true', function () {
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
it('Raw file=false, buffer=true, stream=true', () => {
|
||||
['input', 'output'].forEach((direction) => {
|
||||
assert.strictEqual(false, sharp.format.raw[direction].file);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].buffer);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].stream);
|
||||
});
|
||||
});
|
||||
it('vips format supports filesystem only', function () {
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
it('vips format supports filesystem only', () => {
|
||||
['input', 'output'].forEach((direction) => {
|
||||
assert.strictEqual(true, sharp.format.vips[direction].file);
|
||||
assert.strictEqual(false, sharp.format.vips[direction].buffer);
|
||||
assert.strictEqual(false, sharp.format.vips[direction].stream);
|
||||
});
|
||||
});
|
||||
it('input fileSuffix', function () {
|
||||
it('input fileSuffix', () => {
|
||||
assert.deepStrictEqual(['.jpg', '.jpeg', '.jpe', '.jfif'], sharp.format.jpeg.input.fileSuffix);
|
||||
});
|
||||
it('output alias', function () {
|
||||
it('output alias', () => {
|
||||
assert.deepStrictEqual(['jpe', 'jpg'], sharp.format.jpeg.output.alias);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Versions', function () {
|
||||
it('Contains expected attributes', function () {
|
||||
describe('Versions', () => {
|
||||
it('Contains expected attributes', () => {
|
||||
assert.strictEqual('object', typeof sharp.versions);
|
||||
assert(semver.valid(sharp.versions.vips));
|
||||
assert(semver.valid(sharp.versions.sharp));
|
||||
|
||||
@ -10,12 +10,12 @@ const assert = require('node:assert');
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('WebP', function () {
|
||||
it('WebP output', function (_t, done) {
|
||||
describe('WebP', () => {
|
||||
it('WebP output', (_t, done) => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.toFormat(sharp.format.webp)
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -25,22 +25,22 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid WebP quality throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid WebP quality throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().webp({ quality: 101 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid WebP alpha quality throws error', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid WebP alpha quality throws error', () => {
|
||||
assert.throws(() => {
|
||||
sharp().webp({ alphaQuality: 101 });
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp alpha quality', function (_t, done) {
|
||||
it('should work for webp alpha quality', (_t, done) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({ alphaQuality: 80, effort: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -48,10 +48,10 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp lossless', function (_t, done) {
|
||||
it('should work for webp lossless', (_t, done) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({ lossless: true, effort: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -59,10 +59,10 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp near-lossless', function (_t, done) {
|
||||
it('should work for webp near-lossless', (_t, done) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({ nearLossless: true, quality: 50, effort: 0 })
|
||||
.toBuffer(function (err50, data50, info50) {
|
||||
.toBuffer((err50, data50, info50) => {
|
||||
if (err50) throw err50;
|
||||
assert.strictEqual(true, data50.length > 0);
|
||||
assert.strictEqual('webp', info50.format);
|
||||
@ -70,10 +70,10 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should use near-lossless when both lossless and nearLossless are specified', function (_t, done) {
|
||||
it('should use near-lossless when both lossless and nearLossless are specified', (_t, done) => {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({ nearLossless: true, quality: 50, lossless: true, effort: 0 })
|
||||
.toBuffer(function (err50, data50, info50) {
|
||||
.toBuffer((err50, data50, info50) => {
|
||||
if (err50) throw err50;
|
||||
assert.strictEqual(true, data50.length > 0);
|
||||
assert.strictEqual('webp', info50.format);
|
||||
@ -272,11 +272,11 @@ describe('WebP', function () {
|
||||
assert.deepStrictEqual(updated.delay, [120, 120, 90, 120, 120, 90, 120, 90, 30]);
|
||||
});
|
||||
|
||||
it('should work with streams when only animated is set', function (_t, done) {
|
||||
it('should work with streams when only animated is set', (_t, done) => {
|
||||
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||
.pipe(sharp({ animated: true }))
|
||||
.webp({ lossless: true, effort: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
@ -284,11 +284,11 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with streams when only pages is set', function (_t, done) {
|
||||
it('should work with streams when only pages is set', (_t, done) => {
|
||||
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||
.pipe(sharp({ pages: -1 }))
|
||||
.webp({ lossless: true, effort: 0 })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user