mirror of
https://github.com/lovell/sharp.git
synced 2025-12-06 03:51:40 +01:00
Migrate from mocha to Node.js native test runner
Includes coverage reports when using Node.js 22 onwards
This commit is contained in:
parent
c446d743a2
commit
f2978651f0
@ -14,4 +14,4 @@ task:
|
|||||||
install_script:
|
install_script:
|
||||||
- npm install --build-from-source
|
- npm install --build-from-source
|
||||||
test_script:
|
test_script:
|
||||||
- npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
- node --test test/unit/io.js
|
||||||
|
|||||||
3
.github/CONTRIBUTING.md
vendored
3
.github/CONTRIBUTING.md
vendored
@ -6,8 +6,6 @@ Hello, thank you for your interest in helping!
|
|||||||
|
|
||||||
Please create a [new issue](https://github.com/lovell/sharp/issues/new) containing the steps to reproduce the problem.
|
Please create a [new issue](https://github.com/lovell/sharp/issues/new) containing the steps to reproduce the problem.
|
||||||
|
|
||||||
If you're having installation problems, please include the output of running `npm install --verbose sharp`.
|
|
||||||
|
|
||||||
New bugs are assigned a `triage` label whilst under investigation.
|
New bugs are assigned a `triage` label whilst under investigation.
|
||||||
|
|
||||||
## Submit a new feature request
|
## Submit a new feature request
|
||||||
@ -32,7 +30,6 @@ To test C++ changes, you can compile the module using `npm install --build-from-
|
|||||||
## Submit a Pull Request with a new feature
|
## Submit a Pull Request with a new feature
|
||||||
|
|
||||||
Please add JavaScript [unit tests](https://github.com/lovell/sharp/tree/main/test/unit) to cover your new feature.
|
Please add JavaScript [unit tests](https://github.com/lovell/sharp/tree/main/test/unit) to cover your new feature.
|
||||||
A test coverage report for the JavaScript code is generated in the `coverage/lcov-report` directory.
|
|
||||||
Please also update the [TypeScript definitions](https://github.com/lovell/sharp/tree/main/lib/index.d.ts), along with the [type definition tests](https://github.com/lovell/sharp/tree/main/test/types/sharp.test-d.ts).
|
Please also update the [TypeScript definitions](https://github.com/lovell/sharp/tree/main/lib/index.d.ts), along with the [type definition tests](https://github.com/lovell/sharp/tree/main/test/types/sharp.test-d.ts).
|
||||||
|
|
||||||
Where possible, the functional tests use gradient-based perceptual hashes
|
Where possible, the functional tests use gradient-based perceptual hashes
|
||||||
|
|||||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -267,7 +267,7 @@ jobs:
|
|||||||
curl --silent https://${{ matrix.nodejs_hostname }}/download/release/v${{ matrix.nodejs_version}}/node-v${{ matrix.nodejs_version}}-linux-${{ matrix.nodejs_arch }}.tar.xz | tar xJC /opt/nodejs --strip-components=1
|
curl --silent https://${{ matrix.nodejs_hostname }}/download/release/v${{ matrix.nodejs_version}}/node-v${{ matrix.nodejs_version}}-linux-${{ matrix.nodejs_arch }}.tar.xz | tar xJC /opt/nodejs --strip-components=1
|
||||||
export PATH=$PATH:/opt/nodejs/bin
|
export PATH=$PATH:/opt/nodejs/bin
|
||||||
npm install --build-from-source
|
npm install --build-from-source
|
||||||
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
node --test test/unit/io.js
|
||||||
npm run package-from-local-build
|
npm run package-from-local-build
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"parallel": true,
|
|
||||||
"slow": 1000,
|
|
||||||
"timeout": 30000,
|
|
||||||
"require": "./test/beforeEach.js",
|
|
||||||
"spec": "./test/unit/*.js"
|
|
||||||
}
|
|
||||||
@ -524,9 +524,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
function _write (chunk, _encoding, callback) {
|
function _write (chunk, _encoding, callback) {
|
||||||
/* istanbul ignore else */
|
|
||||||
if (Array.isArray(this.options.input.buffer)) {
|
if (Array.isArray(this.options.input.buffer)) {
|
||||||
/* istanbul ignore else */
|
|
||||||
if (is.buffer(chunk)) {
|
if (is.buffer(chunk)) {
|
||||||
if (this.options.input.buffer.length === 0) {
|
if (this.options.input.buffer.length === 0) {
|
||||||
this.on('finish', () => {
|
this.on('finish', () => {
|
||||||
|
|||||||
@ -10,8 +10,8 @@ const detectLibc = require('detect-libc');
|
|||||||
|
|
||||||
const { config, engines, optionalDependencies } = require('../package.json');
|
const { config, engines, optionalDependencies } = require('../package.json');
|
||||||
|
|
||||||
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */
|
/* node:coverage ignore next */
|
||||||
config.libvips;
|
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || config.libvips;
|
||||||
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
||||||
|
|
||||||
const prebuiltPlatforms = [
|
const prebuiltPlatforms = [
|
||||||
@ -34,17 +34,16 @@ const log = (item) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* node:coverage ignore next */
|
||||||
const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
|
const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
|
||||||
|
|
||||||
const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
|
const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
const buildPlatformArch = () => {
|
const buildPlatformArch = () => {
|
||||||
|
/* node:coverage ignore next 3 */
|
||||||
if (isEmscripten()) {
|
if (isEmscripten()) {
|
||||||
return 'wasm32';
|
return 'wasm32';
|
||||||
}
|
}
|
||||||
/* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
|
|
||||||
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
||||||
const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc();
|
const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc();
|
||||||
return `${npm_config_platform || process.platform}${libc}-${npm_config_arch || process.arch}`;
|
return `${npm_config_platform || process.platform}${libc}-${npm_config_arch || process.arch}`;
|
||||||
@ -54,19 +53,19 @@ const buildSharpLibvipsIncludeDir = () => {
|
|||||||
try {
|
try {
|
||||||
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
|
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
|
||||||
} catch {
|
} catch {
|
||||||
|
/* node:coverage ignore next 5 */
|
||||||
try {
|
try {
|
||||||
return require('@img/sharp-libvips-dev/include');
|
return require('@img/sharp-libvips-dev/include');
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildSharpLibvipsCPlusPlusDir = () => {
|
const buildSharpLibvipsCPlusPlusDir = () => {
|
||||||
|
/* node:coverage ignore next 4 */
|
||||||
try {
|
try {
|
||||||
return require('@img/sharp-libvips-dev/cplusplus');
|
return require('@img/sharp-libvips-dev/cplusplus');
|
||||||
} catch {}
|
} catch {}
|
||||||
/* istanbul ignore next */
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,16 +73,17 @@ const buildSharpLibvipsLibDir = () => {
|
|||||||
try {
|
try {
|
||||||
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
|
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
|
||||||
} catch {
|
} catch {
|
||||||
|
/* node:coverage ignore next 5 */
|
||||||
try {
|
try {
|
||||||
return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
|
return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* node:coverage disable */
|
||||||
|
|
||||||
const isUnsupportedNodeRuntime = () => {
|
const isUnsupportedNodeRuntime = () => {
|
||||||
/* istanbul ignore next */
|
|
||||||
if (process.release?.name === 'node' && process.versions) {
|
if (process.release?.name === 'node' && process.versions) {
|
||||||
if (!semverSatisfies(process.versions.node, engines.node)) {
|
if (!semverSatisfies(process.versions.node, engines.node)) {
|
||||||
return { found: process.versions.node, expected: engines.node };
|
return { found: process.versions.node, expected: engines.node };
|
||||||
@ -91,14 +91,12 @@ const isUnsupportedNodeRuntime = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
const isEmscripten = () => {
|
const isEmscripten = () => {
|
||||||
const { CC } = process.env;
|
const { CC } = process.env;
|
||||||
return Boolean(CC?.endsWith('/emcc'));
|
return Boolean(CC?.endsWith('/emcc'));
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRosetta = () => {
|
const isRosetta = () => {
|
||||||
/* istanbul ignore next */
|
|
||||||
if (process.platform === 'darwin' && process.arch === 'x64') {
|
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||||
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
||||||
return (translated || '').trim() === 'sysctl.proc_translated: 1';
|
return (translated || '').trim() === 'sysctl.proc_translated: 1';
|
||||||
@ -106,6 +104,8 @@ const isRosetta = () => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* node:coverage enable */
|
||||||
|
|
||||||
const sha512 = (s) => createHash('sha512').update(s).digest('hex');
|
const sha512 = (s) => createHash('sha512').update(s).digest('hex');
|
||||||
|
|
||||||
const yarnLocator = () => {
|
const yarnLocator = () => {
|
||||||
@ -119,7 +119,8 @@ const yarnLocator = () => {
|
|||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* node:coverage disable */
|
||||||
|
|
||||||
const spawnRebuild = () =>
|
const spawnRebuild = () =>
|
||||||
spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
|
spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
|
||||||
...spawnSyncOptions,
|
...spawnSyncOptions,
|
||||||
@ -135,16 +136,17 @@ const globalLibvipsVersion = () => {
|
|||||||
PKG_CONFIG_PATH: pkgConfigPath()
|
PKG_CONFIG_PATH: pkgConfigPath()
|
||||||
}
|
}
|
||||||
}).stdout;
|
}).stdout;
|
||||||
/* istanbul ignore next */
|
|
||||||
return (globalLibvipsVersion || '').trim();
|
return (globalLibvipsVersion || '').trim();
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* node:coverage enable */
|
||||||
|
|
||||||
const pkgConfigPath = () => {
|
const pkgConfigPath = () => {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
|
/* node:coverage ignore next 4 */
|
||||||
const brewPkgConfigPath = spawnSync(
|
const brewPkgConfigPath = spawnSync(
|
||||||
'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
|
'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
|
||||||
spawnSyncOptions
|
spawnSyncOptions
|
||||||
@ -176,13 +178,13 @@ const useGlobalLibvips = (logger) => {
|
|||||||
if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
|
if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
|
||||||
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', logger);
|
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', logger);
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
/* node:coverage ignore next 3 */
|
||||||
if (isRosetta()) {
|
if (isRosetta()) {
|
||||||
return skipSearch(false, 'Rosetta', logger);
|
return skipSearch(false, 'Rosetta', logger);
|
||||||
}
|
}
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && /* istanbul ignore next */
|
/* node:coverage ignore next */
|
||||||
semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
|
return !!globalVipsVersion && semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -843,7 +843,6 @@ function gif (options) {
|
|||||||
return this._updateFormatOut('gif', options);
|
return this._updateFormatOut('gif', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
/**
|
/**
|
||||||
* Use these JP2 options for output image.
|
* Use these JP2 options for output image.
|
||||||
*
|
*
|
||||||
@ -878,6 +877,7 @@ function gif (options) {
|
|||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
function jp2 (options) {
|
function jp2 (options) {
|
||||||
|
/* node:coverage ignore next 41 */
|
||||||
if (!this.constructor.format.jp2k.output.buffer) {
|
if (!this.constructor.format.jp2k.output.buffer) {
|
||||||
throw errJp2Save();
|
throw errJp2Save();
|
||||||
}
|
}
|
||||||
@ -1500,7 +1500,6 @@ function _setBooleanOption (key, val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _read () {
|
function _read () {
|
||||||
/* istanbul ignore else */
|
|
||||||
if (!this.options.streamOut) {
|
if (!this.options.streamOut) {
|
||||||
this.options.streamOut = true;
|
this.options.streamOut = true;
|
||||||
const stack = Error();
|
const stack = Error();
|
||||||
|
|||||||
@ -15,6 +15,8 @@ const paths = [
|
|||||||
'@img/sharp-wasm32/sharp.node'
|
'@img/sharp-wasm32/sharp.node'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/* node:coverage disable */
|
||||||
|
|
||||||
let path, sharp;
|
let path, sharp;
|
||||||
const errors = [];
|
const errors = [];
|
||||||
for (path of paths) {
|
for (path of paths) {
|
||||||
@ -22,12 +24,10 @@ for (path of paths) {
|
|||||||
sharp = require(path);
|
sharp = require(path);
|
||||||
break;
|
break;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* istanbul ignore next */
|
|
||||||
errors.push(err);
|
errors.push(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
|
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
|
||||||
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
|
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
|
||||||
err.code = 'Unsupported CPU';
|
err.code = 'Unsupported CPU';
|
||||||
@ -35,7 +35,6 @@ if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2())
|
|||||||
sharp = null;
|
sharp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (sharp) {
|
if (sharp) {
|
||||||
module.exports = sharp;
|
module.exports = sharp;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -55,7 +55,7 @@ const interpolators = {
|
|||||||
let versions = {
|
let versions = {
|
||||||
vips: libvipsVersion.semver
|
vips: libvipsVersion.semver
|
||||||
};
|
};
|
||||||
/* istanbul ignore next */
|
/* node:coverage ignore next 15 */
|
||||||
if (!libvipsVersion.isGlobal) {
|
if (!libvipsVersion.isGlobal) {
|
||||||
if (!libvipsVersion.isWasm) {
|
if (!libvipsVersion.isWasm) {
|
||||||
try {
|
try {
|
||||||
@ -73,7 +73,7 @@ if (!libvipsVersion.isGlobal) {
|
|||||||
}
|
}
|
||||||
versions.sharp = require('../package.json').version;
|
versions.sharp = require('../package.json').version;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* node:coverage ignore next 5 */
|
||||||
if (versions.heif && format.heif) {
|
if (versions.heif && format.heif) {
|
||||||
// Prebuilt binaries provide AV1
|
// Prebuilt binaries provide AV1
|
||||||
format.heif.input.fileSuffix = ['.avif'];
|
format.heif.input.fileSuffix = ['.avif'];
|
||||||
@ -148,7 +148,7 @@ cache(true);
|
|||||||
function concurrency (concurrency) {
|
function concurrency (concurrency) {
|
||||||
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
/* node:coverage ignore next 7 */
|
||||||
if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
||||||
// Reduce default concurrency to 1 when using glibc memory allocator
|
// Reduce default concurrency to 1 when using glibc memory allocator
|
||||||
sharp.concurrency(1);
|
sharp.concurrency(1);
|
||||||
|
|||||||
14
package.json
14
package.json
@ -99,9 +99,9 @@
|
|||||||
"lint-cpp": "cpplint",
|
"lint-cpp": "cpplint",
|
||||||
"lint-js": "biome lint",
|
"lint-js": "biome lint",
|
||||||
"lint-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
|
"lint-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
|
||||||
"lint-types": "tsd",
|
"lint-types": "tsd --files ./test/types/sharp.test-d.ts",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
"test-unit": "node --experimental-test-coverage test/unit.mjs",
|
||||||
"package-from-local-build": "node npm/from-local-build.js",
|
"package-from-local-build": "node npm/from-local-build.js",
|
||||||
"package-release-notes": "node npm/release-notes.js",
|
"package-release-notes": "node npm/release-notes.js",
|
||||||
"docs-build": "node docs/build.mjs",
|
"docs-build": "node docs/build.mjs",
|
||||||
@ -183,10 +183,8 @@
|
|||||||
"icc": "^3.0.0",
|
"icc": "^3.0.0",
|
||||||
"jsdoc-to-markdown": "^9.1.2",
|
"jsdoc-to-markdown": "^9.1.2",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^11.7.2",
|
|
||||||
"node-addon-api": "^8.5.0",
|
"node-addon-api": "^8.5.0",
|
||||||
"node-gyp": "^11.4.2",
|
"node-gyp": "^11.4.2",
|
||||||
"nyc": "^17.1.0",
|
|
||||||
"tar-fs": "^3.1.1",
|
"tar-fs": "^3.1.1",
|
||||||
"tsd": "^0.33.0"
|
"tsd": "^0.33.0"
|
||||||
},
|
},
|
||||||
@ -205,13 +203,5 @@
|
|||||||
"filter": [
|
"filter": [
|
||||||
"build/include"
|
"build/include"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"nyc": {
|
|
||||||
"include": [
|
|
||||||
"lib"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"tsd": {
|
|
||||||
"directory": "test/types/"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
const sharp = require('../');
|
|
||||||
|
|
||||||
const usingCache = !process.env.G_DEBUG;
|
|
||||||
const usingSimd = !process.env.VIPS_NOVECTOR;
|
|
||||||
const concurrency = Number(process.env.VIPS_CONCURRENCY) || 0;
|
|
||||||
|
|
||||||
exports.mochaHooks = {
|
|
||||||
beforeEach () {
|
|
||||||
sharp.cache(usingCache);
|
|
||||||
sharp.simd(usingSimd);
|
|
||||||
sharp.concurrency(concurrency);
|
|
||||||
},
|
|
||||||
|
|
||||||
afterEach () {
|
|
||||||
if (global.gc) {
|
|
||||||
global.gc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -18,5 +18,5 @@ for test in $TESTS; do
|
|||||||
--show-leak-kinds=definite,indirect \
|
--show-leak-kinds=definite,indirect \
|
||||||
--num-callers=20 \
|
--num-callers=20 \
|
||||||
--trace-children=yes \
|
--trace-children=yes \
|
||||||
node --expose-gc --zero-fill-buffers node_modules/.bin/mocha --no-config --slow=60000 --timeout=120000 --require test/beforeEach.js "test/unit/$test";
|
node --zero-fill-buffers --test "test/unit/$test";
|
||||||
done
|
done
|
||||||
|
|||||||
16
test/unit.mjs
Normal file
16
test/unit.mjs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { readdir } from 'node:fs/promises';
|
||||||
|
import { run } from 'node:test';
|
||||||
|
import { spec } from 'node:test/reporters';
|
||||||
|
|
||||||
|
const files = (await readdir('./test/unit')).map((f) => `./test/unit/${f}`);
|
||||||
|
|
||||||
|
run({
|
||||||
|
files,
|
||||||
|
concurrency: true,
|
||||||
|
timeout: 60000,
|
||||||
|
coverage: true,
|
||||||
|
coverageIncludeGlobs: ['lib/*.js'],
|
||||||
|
branchCoverage: 100,
|
||||||
|
})
|
||||||
|
.compose(new spec())
|
||||||
|
.pipe(process.stdout);
|
||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|
||||||
describe('Alpha transparency', function () {
|
describe('Alpha transparency', function () {
|
||||||
it('Flatten to black', function (done) {
|
it('Flatten to black', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten()
|
.flatten()
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
@ -18,7 +19,7 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to RGB orange', function (done) {
|
it('Flatten to RGB orange', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.flatten({
|
.flatten({
|
||||||
@ -33,7 +34,7 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten to CSS/hex orange', function (done) {
|
it('Flatten to CSS/hex orange', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(400, 300)
|
.resize(400, 300)
|
||||||
.flatten({ background: '#ff6600' })
|
.flatten({ background: '#ff6600' })
|
||||||
@ -46,7 +47,7 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flatten 16-bit PNG with transparency to orange', function (done) {
|
it('Flatten 16-bit PNG with transparency to orange', function (_t, done) {
|
||||||
const output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
const output = fixtures.path('output.flatten-rgb16-orange.jpg');
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.flatten({
|
.flatten({
|
||||||
@ -62,7 +63,7 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not flatten', function (done) {
|
it('Do not flatten', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.flatten(false)
|
.flatten(false)
|
||||||
.toBuffer(function (err, _data, info) {
|
.toBuffer(function (err, _data, info) {
|
||||||
@ -73,7 +74,7 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Ignored for JPEG', function (done) {
|
it('Ignored for JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.flatten({ background: '#ff0000' })
|
.flatten({ background: '#ff0000' })
|
||||||
.toBuffer(function (err, _data, info) {
|
.toBuffer(function (err, _data, info) {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -172,9 +173,10 @@ describe('AVIF', () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Invalid bitdepth value throws error', async () => {
|
it('Invalid bitdepth value throws error', () =>
|
||||||
assert.rejects(
|
assert.throws(
|
||||||
() => sharp().avif({ bitdepth: 11 }),
|
() => sharp().avif({ bitdepth: 11 }),
|
||||||
/Error: Expected 8, 10 or 12 for bitdepth but received 11 of type number/);
|
/Expected 8, 10 or 12 for bitdepth but received 11 of type number/
|
||||||
});
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -12,7 +13,7 @@ describe('Bandbool per-channel boolean operations', function () {
|
|||||||
sharp.bool.eor
|
sharp.bool.eor
|
||||||
]
|
]
|
||||||
.forEach(function (op) {
|
.forEach(function (op) {
|
||||||
it(`${op} operation`, function (done) {
|
it(`${op} operation`, function (_t, done) {
|
||||||
sharp(fixtures.inputPngBooleanNoAlpha)
|
sharp(fixtures.inputPngBooleanNoAlpha)
|
||||||
.bandbool(op)
|
.bandbool(op)
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
@ -26,7 +27,7 @@ describe('Bandbool per-channel boolean operations', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sRGB image retains 3 channels', function (done) {
|
it('sRGB image retains 3 channels', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.bandbool('and')
|
.bandbool('and')
|
||||||
.toBuffer(function (err, _data, info) {
|
.toBuffer(function (err, _data, info) {
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Blur', function () {
|
describe('Blur', function () {
|
||||||
it('specific radius 1', function (done) {
|
it('specific radius 1', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(1)
|
.blur(1)
|
||||||
@ -20,7 +21,7 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 10', function (done) {
|
it('specific radius 10', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(10)
|
.blur(10)
|
||||||
@ -33,7 +34,7 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific options.sigma 10', function (done) {
|
it('specific options.sigma 10', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur({ sigma: 10 })
|
.blur({ sigma: 10 })
|
||||||
@ -46,7 +47,7 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 0.3', function (done) {
|
it('specific radius 0.3', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(0.3)
|
.blur(0.3)
|
||||||
@ -59,7 +60,7 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('mild blur', function (done) {
|
it('mild blur', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur()
|
.blur()
|
||||||
@ -78,7 +79,7 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('blurred image is smaller than non-blurred', function (done) {
|
it('blurred image is smaller than non-blurred', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.blur(false)
|
.blur(false)
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
@ -16,7 +17,7 @@ describe('Boolean operation between two images', function () {
|
|||||||
sharp.bool.eor
|
sharp.bool.eor
|
||||||
]
|
]
|
||||||
.forEach(function (op) {
|
.forEach(function (op) {
|
||||||
it(`${op} operation, file`, function (done) {
|
it(`${op} operation, file`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.boolean(fixtures.inputJpgBooleanTest, op)
|
.boolean(fixtures.inputJpgBooleanTest, op)
|
||||||
@ -28,7 +29,7 @@ describe('Boolean operation between two images', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`${op} operation, buffer`, function (done) {
|
it(`${op} operation, buffer`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.boolean(inputJpgBooleanTestBuffer, op)
|
.boolean(inputJpgBooleanTestBuffer, op)
|
||||||
@ -40,7 +41,7 @@ describe('Boolean operation between two images', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`${op} operation, raw`, function (done) {
|
it(`${op} operation, raw`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpgBooleanTest)
|
sharp(fixtures.inputJpgBooleanTest)
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../lib');
|
const sharp = require('../../lib');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Clahe', function () {
|
describe('Clahe', function () {
|
||||||
it('width 5 width 5 maxSlope 0', function (done) {
|
it('width 5 width 5 maxSlope 0', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 5, height: 5, maxSlope: 0 })
|
.clahe({ width: 5, height: 5, maxSlope: 0 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -17,7 +18,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 5 width 5 maxSlope 5', function (done) {
|
it('width 5 width 5 maxSlope 5', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 5, height: 5, maxSlope: 5 })
|
.clahe({ width: 5, height: 5, maxSlope: 5 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -27,7 +28,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 11 width 25 maxSlope 14', function (done) {
|
it('width 11 width 25 maxSlope 14', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 11, height: 25, maxSlope: 14 })
|
.clahe({ width: 11, height: 25, maxSlope: 14 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -37,7 +38,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 50 width 50 maxSlope 0', function (done) {
|
it('width 50 width 50 maxSlope 0', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 50, height: 50, maxSlope: 0 })
|
.clahe({ width: 50, height: 50, maxSlope: 0 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -47,7 +48,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 50 width 50 maxSlope 14', function (done) {
|
it('width 50 width 50 maxSlope 14', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 50, height: 50, maxSlope: 14 })
|
.clahe({ width: 50, height: 50, maxSlope: 14 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -57,7 +58,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 100 width 50 maxSlope 3', function (done) {
|
it('width 100 width 50 maxSlope 3', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 100, height: 50, maxSlope: 3 })
|
.clahe({ width: 100, height: 50, maxSlope: 3 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -67,7 +68,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('width 100 width 100 maxSlope 0', function (done) {
|
it('width 100 width 100 maxSlope 0', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 100, height: 100, maxSlope: 0 })
|
.clahe({ width: 100, height: 100, maxSlope: 0 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -128,7 +129,7 @@ describe('Clahe', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses default maxSlope of 3', function (done) {
|
it('uses default maxSlope of 3', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgClahe)
|
sharp(fixtures.inputJpgClahe)
|
||||||
.clahe({ width: 100, height: 50 })
|
.clahe({ width: 100, height: 50 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { afterEach, beforeEach, describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -15,7 +16,7 @@ describe('Clone', function () {
|
|||||||
sharp.cache(true);
|
sharp.cache(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to multiple Streams', function (done) {
|
it('Read from Stream and write to multiple Streams', function (_t, done) {
|
||||||
let finishEventsExpected = 2;
|
let finishEventsExpected = 2;
|
||||||
// Output stream 1
|
// Output stream 1
|
||||||
const output1 = fixtures.path('output.multi-stream.1.jpg');
|
const output1 = fixtures.path('output.multi-stream.1.jpg');
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Colour space conversion', function () {
|
describe('Colour space conversion', function () {
|
||||||
it('To greyscale', function (done) {
|
it('To greyscale', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('To greyscale with gamma correction', function (done) {
|
it('To greyscale with gamma correction', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.gamma()
|
.gamma()
|
||||||
@ -22,14 +23,14 @@ describe('Colour space conversion', function () {
|
|||||||
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Not to greyscale', function (done) {
|
it('Not to greyscale', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.greyscale(false)
|
.greyscale(false)
|
||||||
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Greyscale with single channel output', function (done) {
|
it('Greyscale with single channel output', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
@ -53,7 +54,7 @@ describe('Colour space conversion', function () {
|
|||||||
assert.strictEqual(format, 'webp');
|
assert.strictEqual(format, 'webp');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From CMYK to sRGB', function (done) {
|
it('From CMYK to sRGB', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -65,7 +66,7 @@ describe('Colour space conversion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From CMYK to sRGB with white background, not yellow', function (done) {
|
it('From CMYK to sRGB with white background, not yellow', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(320, 240, {
|
.resize(320, 240, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -80,7 +81,7 @@ describe('Colour space conversion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From profile-less CMYK to sRGB', function (done) {
|
it('From profile-less CMYK to sRGB', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCmykNoProfile)
|
sharp(fixtures.inputJpgWithCmykNoProfile)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -120,7 +121,7 @@ describe('Colour space conversion', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('CMYK profile to CMYK profile with negate', (done) => {
|
it('CMYK profile to CMYK profile with negate', (_t, done) => {
|
||||||
sharp(fixtures.inputTiffFogra)
|
sharp(fixtures.inputTiffFogra)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toColourspace('cmyk')
|
.toColourspace('cmyk')
|
||||||
@ -141,7 +142,7 @@ describe('Colour space conversion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (done) {
|
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (_t, done) {
|
||||||
sharp(fixtures.inputPngGradients)
|
sharp(fixtures.inputPngGradients)
|
||||||
.pipelineColourspace('rgb16')
|
.pipelineColourspace('rgb16')
|
||||||
.resize(320)
|
.resize(320)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Convolve', function () {
|
describe('Convolve', function () {
|
||||||
it('specific convolution kernel 1', function (done) {
|
it('specific convolution kernel 1', function (_t, done) {
|
||||||
sharp(fixtures.inputPngStripesV)
|
sharp(fixtures.inputPngStripesV)
|
||||||
.convolve({
|
.convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -29,7 +30,7 @@ describe('Convolve', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific convolution kernel 2', function (done) {
|
it('specific convolution kernel 2', function (_t, done) {
|
||||||
sharp(fixtures.inputPngStripesH)
|
sharp(fixtures.inputPngStripesH)
|
||||||
.convolve({
|
.convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -49,7 +50,7 @@ describe('Convolve', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('horizontal Sobel operator', function (done) {
|
it('horizontal Sobel operator', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.convolve({
|
.convolve({
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Dilate', function () {
|
describe('Dilate', function () {
|
||||||
it('dilate 1 png', function (done) {
|
it('dilate 1 png', function (_t, done) {
|
||||||
sharp(fixtures.inputPngDotAndLines)
|
sharp(fixtures.inputPngDotAndLines)
|
||||||
.dilate(1)
|
.dilate(1)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -16,7 +17,7 @@ describe('Dilate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dilate 1 png - default width', function (done) {
|
it('dilate 1 png - default width', function (_t, done) {
|
||||||
sharp(fixtures.inputPngDotAndLines)
|
sharp(fixtures.inputPngDotAndLines)
|
||||||
.dilate()
|
.dilate()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Erode', function () {
|
describe('Erode', function () {
|
||||||
it('erode 1 png', function (done) {
|
it('erode 1 png', function (_t, done) {
|
||||||
sharp(fixtures.inputPngDotAndLines)
|
sharp(fixtures.inputPngDotAndLines)
|
||||||
.erode(1)
|
.erode(1)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -16,7 +17,7 @@ describe('Erode', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('erode 1 png - default width', function (done) {
|
it('erode 1 png - default width', function (_t, done) {
|
||||||
sharp(fixtures.inputPngDotAndLines)
|
sharp(fixtures.inputPngDotAndLines)
|
||||||
.erode()
|
.erode()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -8,7 +9,7 @@ const fixtures = require('../fixtures');
|
|||||||
|
|
||||||
describe('Extend', function () {
|
describe('Extend', function () {
|
||||||
describe('extend all sides equally via a single value', function () {
|
describe('extend all sides equally via a single value', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.extend(10)
|
.extend(10)
|
||||||
@ -20,7 +21,7 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Animated WebP', function (done) {
|
it('Animated WebP', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.extend(10)
|
.extend(10)
|
||||||
@ -34,7 +35,7 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
['background', 'copy', 'mirror', 'repeat'].forEach(extendWith => {
|
['background', 'copy', 'mirror', 'repeat'].forEach(extendWith => {
|
||||||
it(`extends all sides with animated WebP (${extendWith})`, function (done) {
|
it(`extends all sides with animated WebP (${extendWith})`, function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.extend({
|
.extend({
|
||||||
@ -52,7 +53,7 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`extend all sides equally with RGB (${extendWith})`, function (done) {
|
it(`extend all sides equally with RGB (${extendWith})`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.extend({
|
.extend({
|
||||||
@ -71,7 +72,7 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`extend sides unequally with RGBA (${extendWith})`, function (done) {
|
it(`extend sides unequally with RGBA (${extendWith})`, function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
.extend({
|
.extend({
|
||||||
@ -89,7 +90,7 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`PNG with 2 channels (${extendWith})`, function (done) {
|
it(`PNG with 2 channels (${extendWith})`, function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extend({
|
.extend({
|
||||||
extendWith,
|
extendWith,
|
||||||
@ -188,7 +189,7 @@ describe('Extend', function () {
|
|||||||
assert.doesNotThrow(() => sharp().extend({ top: 1, left: 2, bottom: 3 }));
|
assert.doesNotThrow(() => sharp().extend({ top: 1, left: 2, bottom: 3 }));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add alpha channel before extending with a transparent Background', function (done) {
|
it('should add alpha channel before extending with a transparent Background', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.extend({
|
.extend({
|
||||||
bottom: 10,
|
bottom: 10,
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Partial image extraction', function () {
|
describe('Partial image extraction', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
.extract({ left: 2, top: 2, width: 20, height: 20 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -18,7 +19,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function (done) {
|
it('PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
.extract({ left: 200, top: 300, width: 400, height: 200 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -29,7 +30,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('WebP', function (done) {
|
it('WebP', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
.extract({ left: 100, top: 50, width: 125, height: 200 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -41,7 +42,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated WebP', function () {
|
describe('Animated WebP', function () {
|
||||||
it('Before resize', function (done) {
|
it('Before resize', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.extract({ left: 0, top: 30, width: 80, height: 20 })
|
.extract({ left: 0, top: 30, width: 80, height: 20 })
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
@ -53,7 +54,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('After resize', function (done) {
|
it('After resize', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(320, 320)
|
.resize(320, 320)
|
||||||
.extract({ left: 0, top: 120, width: 320, height: 80 })
|
.extract({ left: 0, top: 120, width: 320, height: 80 })
|
||||||
@ -66,7 +67,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF', function (done) {
|
it('TIFF', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
.extract({ left: 34, top: 63, width: 341, height: 529 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -77,7 +78,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Before resize', function (done) {
|
it('Before resize', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
.extract({ left: 10, top: 10, width: 10, height: 500 })
|
||||||
.resize(100, 100)
|
.resize(100, 100)
|
||||||
@ -89,7 +90,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('After resize and crop', function (done) {
|
it('After resize and crop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(500, 500, {
|
.resize(500, 500, {
|
||||||
position: sharp.gravity.north
|
position: sharp.gravity.north
|
||||||
@ -103,7 +104,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Before and after resize and crop', function (done) {
|
it('Before and after resize and crop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
.extract({ left: 0, top: 0, width: 700, height: 700 })
|
||||||
.resize(500, 500, {
|
.resize(500, 500, {
|
||||||
@ -118,7 +119,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Extract then rotate', function (done) {
|
it('Extract then rotate', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
@ -131,7 +132,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate then extract', function (done) {
|
it('Rotate then extract', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
.extract({ left: 20, top: 10, width: 280, height: 380 })
|
||||||
@ -143,7 +144,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Extract then rotate then extract', function (done) {
|
it('Extract then rotate then extract', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extract({ left: 20, top: 10, width: 180, height: 280 })
|
.extract({ left: 20, top: 10, width: 180, height: 280 })
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
@ -156,7 +157,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Extract then rotate non-90 anagle', function (done) {
|
it('Extract then rotate non-90 anagle', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||||
.rotate(45)
|
.rotate(45)
|
||||||
@ -169,7 +170,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate then extract non-90 angle', function (done) {
|
it('Rotate then extract non-90 angle', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.rotate(45)
|
.rotate(45)
|
||||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||||
@ -217,7 +218,7 @@ describe('Partial image extraction', function () {
|
|||||||
image: fixtures.inputJpgWithLandscapeExif8
|
image: fixtures.inputJpgWithLandscapeExif8
|
||||||
}
|
}
|
||||||
].forEach(({ name, image }) => {
|
].forEach(({ name, image }) => {
|
||||||
it(name, function (done) {
|
it(name, function (_t, done) {
|
||||||
sharp(image)
|
sharp(image)
|
||||||
.rotate()
|
.rotate()
|
||||||
.extract({ left: 0, top: 208, width: 60, height: 40 })
|
.extract({ left: 0, top: 208, width: 60, height: 40 })
|
||||||
@ -286,7 +287,7 @@ describe('Partial image extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Bad image area', function (done) {
|
it('Bad image area', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
.extract({ left: 3000, top: 10, width: 10, height: 10 })
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Image channel extraction', function () {
|
describe('Image channel extraction', function () {
|
||||||
it('Red channel', function (done) {
|
it('Red channel', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('red')
|
.extractChannel('red')
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -19,7 +20,7 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Green channel', function (done) {
|
it('Green channel', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('green')
|
.extractChannel('green')
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -31,7 +32,7 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Blue channel', function (done) {
|
it('Blue channel', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel('blue')
|
.extractChannel('blue')
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -43,7 +44,7 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Blue channel by number', function (done) {
|
it('Blue channel by number', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extractChannel(2)
|
.extractChannel(2)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -64,7 +65,7 @@ describe('Image channel extraction', function () {
|
|||||||
assert.strictEqual(chroma, 104);
|
assert.strictEqual(chroma, 104);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Alpha from 16-bit PNG', function (done) {
|
it('Alpha from 16-bit PNG', function (_t, done) {
|
||||||
const output = fixtures.path('output.extract-alpha-16bit.png');
|
const output = fixtures.path('output.extract-alpha-16bit.png');
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(16)
|
.resize(16)
|
||||||
@ -76,7 +77,7 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Alpha from 2-channel input', function (done) {
|
it('Alpha from 2-channel input', function (_t, done) {
|
||||||
const output = fixtures.path('output.extract-alpha-2-channel.png');
|
const output = fixtures.path('output.extract-alpha-2-channel.png');
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.extractChannel('alpha')
|
.extractChannel('alpha')
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ const sharp = require('../../lib');
|
|||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('failOn', () => {
|
describe('failOn', () => {
|
||||||
it('handles truncated JPEG', function (done) {
|
it('handles truncated JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgTruncated, { failOn: 'none' })
|
sharp(fixtures.inputJpgTruncated, { failOn: 'none' })
|
||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -20,7 +21,7 @@ describe('failOn', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles truncated PNG, emits warnings', function (done) {
|
it('handles truncated PNG, emits warnings', function (_t, done) {
|
||||||
let isWarningEmitted = false;
|
let isWarningEmitted = false;
|
||||||
sharp(fixtures.inputPngTruncated, { failOn: 'none' })
|
sharp(fixtures.inputPngTruncated, { failOn: 'none' })
|
||||||
.on('warning', function (warning) {
|
.on('warning', function (warning) {
|
||||||
@ -68,7 +69,7 @@ describe('failOn', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns errors to callback for truncated JPEG', function (done) {
|
it('returns errors to callback for truncated JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
||||||
assert.ok(err.message.includes('VipsJpeg: premature end of'), err);
|
assert.ok(err.message.includes('VipsJpeg: premature end of'), err);
|
||||||
assert.strictEqual(data, undefined);
|
assert.strictEqual(data, undefined);
|
||||||
@ -77,7 +78,7 @@ describe('failOn', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns errors to callback for truncated PNG', function (done) {
|
it('returns errors to callback for truncated PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPngTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputPngTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
||||||
assert.ok(err.message.includes('read error'), err);
|
assert.ok(err.message.includes('read error'), err);
|
||||||
assert.strictEqual(data, undefined);
|
assert.strictEqual(data, undefined);
|
||||||
@ -86,7 +87,7 @@ describe('failOn', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects promises for truncated JPEG', function (done) {
|
it('rejects promises for truncated JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgTruncated, { failOn: 'error' })
|
sharp(fixtures.inputJpgTruncated, { failOn: 'error' })
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Gamma correction', function () {
|
describe('Gamma correction', function () {
|
||||||
it('value of 0.0 (disabled)', function (done) {
|
it('value of 0.0 (disabled)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -19,7 +20,7 @@ describe('Gamma correction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('value of 2.2 (default)', function (done) {
|
it('value of 2.2 (default)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.gamma()
|
.gamma()
|
||||||
@ -32,7 +33,7 @@ describe('Gamma correction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('value of 3.0', function (done) {
|
it('value of 3.0', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.gamma(3)
|
.gamma(3)
|
||||||
@ -45,7 +46,7 @@ describe('Gamma correction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('input value of 2.2, output value of 3.0', function (done) {
|
it('input value of 2.2, output value of 3.0', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithGammaHoliness)
|
sharp(fixtures.inputJpgWithGammaHoliness)
|
||||||
.resize(129, 111)
|
.resize(129, 111)
|
||||||
.gamma(2.2, 3.0)
|
.gamma(2.2, 3.0)
|
||||||
@ -58,7 +59,7 @@ describe('Gamma correction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('alpha transparency', function (done) {
|
it('alpha transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.gamma()
|
.gamma()
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -196,7 +197,7 @@ describe('GIF input', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with streams when only animated is set', function (done) {
|
it('should work with streams when only animated is set', function (_t, done) {
|
||||||
fs.createReadStream(fixtures.inputGifAnimated)
|
fs.createReadStream(fixtures.inputGifAnimated)
|
||||||
.pipe(sharp({ animated: true }))
|
.pipe(sharp({ animated: true }))
|
||||||
.gif()
|
.gif()
|
||||||
@ -208,7 +209,7 @@ describe('GIF input', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with streams when only pages is set', function (done) {
|
it('should work with streams when only pages is set', function (_t, done) {
|
||||||
fs.createReadStream(fixtures.inputGifAnimated)
|
fs.createReadStream(fixtures.inputGifAnimated)
|
||||||
.pipe(sharp({ pages: -1 }))
|
.pipe(sharp({ pages: -1 }))
|
||||||
.gif()
|
.gif()
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
|
const { afterEach, beforeEach, describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -18,7 +19,7 @@ describe('Input/output', function () {
|
|||||||
sharp.cache(true);
|
sharp.cache(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from File and write to Stream', function (done) {
|
it('Read from File and write to Stream', function (_t, done) {
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
sharp(outputJpg).toBuffer(function (err, data, info) {
|
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||||
@ -34,7 +35,7 @@ describe('Input/output', function () {
|
|||||||
sharp(fixtures.inputJpg).resize(320, 240).pipe(writable);
|
sharp(fixtures.inputJpg).resize(320, 240).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Buffer and write to Stream', function (done) {
|
it('Read from Buffer and write to Stream', function (_t, done) {
|
||||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
@ -51,7 +52,7 @@ describe('Input/output', function () {
|
|||||||
sharp(inputJpgBuffer).resize(320, 240).pipe(writable);
|
sharp(inputJpgBuffer).resize(320, 240).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to File', function (done) {
|
it('Read from Stream and write to File', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
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, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -64,7 +65,7 @@ describe('Input/output', function () {
|
|||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to Buffer', function (done) {
|
it('Read from Stream and write to Buffer', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) {
|
const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -132,7 +133,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Read from Stream and write to Stream', function (done) {
|
it('Read from Stream and write to Stream', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
@ -217,7 +218,7 @@ describe('Input/output', function () {
|
|||||||
assert.strictEqual(info.height, 1);
|
assert.strictEqual(info.height, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream should emit info event', function (done) {
|
it('Stream should emit info event', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
@ -236,7 +237,7 @@ describe('Input/output', function () {
|
|||||||
readable.pipe(pipeline).pipe(writable);
|
readable.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream should emit close event', function (done) {
|
it('Stream should emit close event', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
@ -251,7 +252,7 @@ describe('Input/output', function () {
|
|||||||
readable.pipe(pipeline).pipe(writable);
|
readable.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handle Stream to Stream error ', function (done) {
|
it('Handle Stream to Stream error ', function (_t, done) {
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
let anErrorWasEmitted = false;
|
let anErrorWasEmitted = false;
|
||||||
pipeline.on('error', function (err) {
|
pipeline.on('error', function (err) {
|
||||||
@ -265,7 +266,7 @@ describe('Input/output', function () {
|
|||||||
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handle File to Stream error', function (done) {
|
it('Handle File to Stream error', function (_t, done) {
|
||||||
const readableButNotAnImage = sharp(__filename).resize(320, 240);
|
const readableButNotAnImage = sharp(__filename).resize(320, 240);
|
||||||
let anErrorWasEmitted = false;
|
let anErrorWasEmitted = false;
|
||||||
readableButNotAnImage.on('error', function (err) {
|
readableButNotAnImage.on('error', function (err) {
|
||||||
@ -278,7 +279,7 @@ describe('Input/output', function () {
|
|||||||
readableButNotAnImage.pipe(writable);
|
readableButNotAnImage.pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Readable side of Stream can start flowing after Writable side has finished', function (done) {
|
it('Readable side of Stream can start flowing after Writable side has finished', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
@ -299,6 +300,20 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Non-Stream input generates error when provided Stream-like data', (_t, done) => {
|
||||||
|
sharp('input')._write('fail', null, (err) => {
|
||||||
|
assert.strictEqual(err.message, 'Unexpected data on Writable Stream');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Non-Buffer chunk on Stream input generates error', (_t, done) => {
|
||||||
|
sharp()._write('fail', null, (err) => {
|
||||||
|
assert.strictEqual(err.message, 'Non-Buffer data on Writable Stream');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Invalid sequential read option throws', () => {
|
it('Invalid sequential read option throws', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
sharp({ sequentialRead: 'fail' });
|
sharp({ sequentialRead: 'fail' });
|
||||||
@ -333,7 +348,7 @@ describe('Input/output', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Support output to jpg format', function (done) {
|
it('Support output to jpg format', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toFormat('jpg')
|
.toFormat('jpg')
|
||||||
@ -348,7 +363,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Support output to tif format', function (done) {
|
it('Support output to tif format', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toFormat('tif')
|
.toFormat('tif')
|
||||||
@ -377,7 +392,7 @@ describe('Input/output', function () {
|
|||||||
assert.strictEqual(Buffer.isBuffer(data), true);
|
assert.strictEqual(Buffer.isBuffer(data), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File', function (done) {
|
it('Fail when output File is input File', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function (err) {
|
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
assert.strictEqual('Cannot use same file for input and output', err.message);
|
assert.strictEqual('Cannot use same file for input and output', err.message);
|
||||||
@ -385,7 +400,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File via Promise', function (done) {
|
it('Fail when output File is input File via Promise', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function () {
|
sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function () {
|
||||||
done(new Error('Unexpectedly resolved Promise'));
|
done(new Error('Unexpectedly resolved Promise'));
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
@ -395,7 +410,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File (relative output, absolute input)', function (done) {
|
it('Fail when output File is input File (relative output, absolute input)', function (_t, done) {
|
||||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||||
sharp(fixtures.inputJpg).toFile(relativePath, function (err) {
|
sharp(fixtures.inputJpg).toFile(relativePath, function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
@ -404,7 +419,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File via Promise (relative output, absolute input)', function (done) {
|
it('Fail when output File is input File via Promise (relative output, absolute input)', function (_t, done) {
|
||||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||||
sharp(fixtures.inputJpg).toFile(relativePath).then(function () {
|
sharp(fixtures.inputJpg).toFile(relativePath).then(function () {
|
||||||
done(new Error('Unexpectedly resolved Promise'));
|
done(new Error('Unexpectedly resolved Promise'));
|
||||||
@ -415,7 +430,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File (relative input, absolute output)', function (done) {
|
it('Fail when output File is input File (relative input, absolute output)', function (_t, done) {
|
||||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||||
sharp(relativePath).toFile(fixtures.inputJpg, function (err) {
|
sharp(relativePath).toFile(fixtures.inputJpg, function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
@ -424,7 +439,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is input File via Promise (relative input, absolute output)', function (done) {
|
it('Fail when output File is input File via Promise (relative input, absolute output)', function (_t, done) {
|
||||||
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
const relativePath = path.relative(process.cwd(), fixtures.inputJpg);
|
||||||
sharp(relativePath).toFile(fixtures.inputJpg).then(function () {
|
sharp(relativePath).toFile(fixtures.inputJpg).then(function () {
|
||||||
done(new Error('Unexpectedly resolved Promise'));
|
done(new Error('Unexpectedly resolved Promise'));
|
||||||
@ -435,7 +450,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is empty', function (done) {
|
it('Fail when output File is empty', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).toFile('', function (err) {
|
sharp(fixtures.inputJpg).toFile('', function (err) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
assert.strictEqual('Missing output file path', err.message);
|
assert.strictEqual('Missing output file path', err.message);
|
||||||
@ -443,7 +458,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when output File is empty via Promise', function (done) {
|
it('Fail when output File is empty via Promise', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).toFile('').then(function () {
|
sharp(fixtures.inputJpg).toFile('').then(function () {
|
||||||
done(new Error('Unexpectedly resolved Promise'));
|
done(new Error('Unexpectedly resolved Promise'));
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
@ -511,7 +526,7 @@ describe('Input/output', function () {
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid output format', function (done) {
|
it('Invalid output format', function (_t, done) {
|
||||||
let isValid = false;
|
let isValid = false;
|
||||||
try {
|
try {
|
||||||
sharp().toFormat('zoinks');
|
sharp().toFormat('zoinks');
|
||||||
@ -521,7 +536,7 @@ describe('Input/output', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('File input with corrupt header fails gracefully', function (done) {
|
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -529,7 +544,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Buffer input with corrupt header fails gracefully', function (done) {
|
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -537,7 +552,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream input with corrupt header fails gracefully', function (done) {
|
it('Stream input with corrupt header fails gracefully', function (_t, done) {
|
||||||
const transformer = sharp();
|
const transformer = sharp();
|
||||||
transformer
|
transformer
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
@ -556,7 +571,7 @@ describe('Input/output', function () {
|
|||||||
describe('Output filename with unknown extension', function () {
|
describe('Output filename with unknown extension', function () {
|
||||||
const outputZoinks = fixtures.path('output.zoinks');
|
const outputZoinks = fixtures.path('output.zoinks');
|
||||||
|
|
||||||
it('Match JPEG input', function (done) {
|
it('Match JPEG input', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
@ -569,7 +584,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match PNG input', function (done) {
|
it('Match PNG input', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
@ -582,7 +597,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match WebP input', function (done) {
|
it('Match WebP input', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
@ -595,7 +610,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match TIFF input', function (done) {
|
it('Match TIFF input', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
@ -608,7 +623,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Force JPEG format for PNG input', function (done) {
|
it('Force JPEG format for PNG input', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -623,7 +638,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input and output formats match when not forcing', function (done) {
|
it('Input and output formats match when not forcing', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.png({ compressionLevel: 1, force: false })
|
.png({ compressionLevel: 1, force: false })
|
||||||
@ -647,7 +662,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toFormat=JPEG takes precedence over WebP extension', function (done) {
|
it('toFormat=JPEG takes precedence over WebP extension', function (_t, done) {
|
||||||
const outputWebP = fixtures.path('output.webp');
|
const outputWebP = fixtures.path('output.webp');
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(8)
|
.resize(8)
|
||||||
@ -659,7 +674,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toFormat=WebP takes precedence over JPEG extension', function (done) {
|
it('toFormat=WebP takes precedence over JPEG extension', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(8)
|
.resize(8)
|
||||||
.webp()
|
.webp()
|
||||||
@ -670,7 +685,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Load Vips V file', function (done) {
|
it('Load Vips V file', function (_t, done) {
|
||||||
sharp(fixtures.inputV)
|
sharp(fixtures.inputV)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -683,7 +698,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Save Vips V file', function (done) {
|
it('Save Vips V file', function (_t, done) {
|
||||||
const outputV = fixtures.path('output.v');
|
const outputV = fixtures.path('output.v');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 910, top: 1105, width: 70, height: 60 })
|
.extract({ left: 910, top: 1105, width: 70, height: 60 })
|
||||||
@ -963,7 +978,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('create new image', function () {
|
describe('create new image', function () {
|
||||||
it('RGB', function (done) {
|
it('RGB', function (_t, done) {
|
||||||
const create = {
|
const create = {
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 20,
|
height: 20,
|
||||||
@ -981,7 +996,7 @@ describe('Input/output', function () {
|
|||||||
fixtures.assertSimilar(fixtures.expected('create-rgb.jpg'), data, done);
|
fixtures.assertSimilar(fixtures.expected('create-rgb.jpg'), data, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('RGBA', function (done) {
|
it('RGBA', function (_t, done) {
|
||||||
const create = {
|
const create = {
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 10,
|
height: 10,
|
||||||
@ -1022,7 +1037,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Queue length change events', function (done) {
|
it('Queue length change events', function (_t, done) {
|
||||||
let eventCounter = 0;
|
let eventCounter = 0;
|
||||||
const queueListener = function (queueLength) {
|
const queueListener = function (queueLength) {
|
||||||
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
assert.strictEqual(true, queueLength === 0 || queueLength === 1);
|
||||||
@ -1041,7 +1056,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Info event data', function (done) {
|
it('Info event data', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
const readable = fs.createReadStream(fixtures.inputJPGBig);
|
||||||
const inPipeline = sharp()
|
const inPipeline = sharp()
|
||||||
.resize(840, 472)
|
.resize(840, 472)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ const sharp = require('../../');
|
|||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Image channel insertion', function () {
|
describe('Image channel insertion', function () {
|
||||||
it('Grayscale to RGB, buffer', function (done) {
|
it('Grayscale to RGB, buffer', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> red
|
sharp(fixtures.inputPng) // gray -> red
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel(fixtures.inputPngTestJoinChannel) // new green channel
|
.joinChannel(fixtures.inputPngTestJoinChannel) // new green channel
|
||||||
@ -22,7 +23,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale to RGB, file', function (done) {
|
it('Grayscale to RGB, file', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> red
|
sharp(fixtures.inputPng) // gray -> red
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel(fs.readFileSync(fixtures.inputPngTestJoinChannel)) // new green channel
|
.joinChannel(fs.readFileSync(fixtures.inputPngTestJoinChannel)) // new green channel
|
||||||
@ -36,7 +37,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale to RGBA, buffer', function (done) {
|
it('Grayscale to RGBA, buffer', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> red
|
sharp(fixtures.inputPng) // gray -> red
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel([
|
.joinChannel([
|
||||||
@ -54,7 +55,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale to RGBA, file', function (done) {
|
it('Grayscale to RGBA, file', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> red
|
sharp(fixtures.inputPng) // gray -> red
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel([
|
.joinChannel([
|
||||||
@ -72,7 +73,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale to CMYK, buffers', function (done) {
|
it('Grayscale to CMYK, buffers', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> magenta
|
sharp(fixtures.inputPng) // gray -> magenta
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel([
|
.joinChannel([
|
||||||
@ -91,7 +92,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Join raw buffers to RGB', function (done) {
|
it('Join raw buffers to RGB', function (_t, done) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
sharp(fixtures.inputPngTestJoinChannel).toColourspace('b-w').raw().toBuffer(),
|
sharp(fixtures.inputPngTestJoinChannel).toColourspace('b-w').raw().toBuffer(),
|
||||||
sharp(fixtures.inputPngStripesH).toColourspace('b-w').raw().toBuffer()
|
sharp(fixtures.inputPngStripesH).toColourspace('b-w').raw().toBuffer()
|
||||||
@ -119,7 +120,7 @@ describe('Image channel insertion', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale to RGBA, files, two arrays', function (done) {
|
it('Grayscale to RGBA, files, two arrays', function (_t, done) {
|
||||||
sharp(fixtures.inputPng) // gray -> red
|
sharp(fixtures.inputPng) // gray -> red
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel)]) // new green channel
|
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel)]) // new green channel
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('JPEG', function () {
|
describe('JPEG', function () {
|
||||||
it('JPEG quality', function (done) {
|
it('JPEG quality', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.jpeg({ quality: 70 })
|
.jpeg({ quality: 70 })
|
||||||
@ -50,7 +51,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Progressive JPEG image', function (done) {
|
it('Progressive JPEG image', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.jpeg({ progressive: false })
|
.jpeg({ progressive: false })
|
||||||
@ -77,7 +78,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Without chroma subsampling generates larger file', function (done) {
|
it('Without chroma subsampling generates larger file', function (_t, done) {
|
||||||
// First generate with chroma subsampling (default)
|
// First generate with chroma subsampling (default)
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -112,7 +113,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Trellis quantisation', function (done) {
|
it('Trellis quantisation', function (_t, done) {
|
||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -142,7 +143,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Overshoot deringing', function (done) {
|
it('Overshoot deringing', function (_t, done) {
|
||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -170,7 +171,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Optimise scans generates different output length', function (done) {
|
it('Optimise scans generates different output length', function (_t, done) {
|
||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -200,7 +201,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Optimise coding generates smaller output length', function (done) {
|
it('Optimise coding generates smaller output length', function (_t, done) {
|
||||||
// First generate with optimize coding enabled (default)
|
// First generate with optimize coding enabled (default)
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -230,7 +231,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Specifying quantisation table provides different JPEG', function (done) {
|
it('Specifying quantisation table provides different JPEG', function (_t, done) {
|
||||||
// First generate with default quantisation table
|
// First generate with default quantisation table
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -261,7 +262,7 @@ describe('JPEG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Specifying quantization table provides different JPEG', function (done) {
|
it('Specifying quantization table provides different JPEG', function (_t, done) {
|
||||||
// First generate with default quantization table
|
// First generate with default quantization table
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { after, before, describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
@ -152,7 +153,7 @@ describe('libvips binaries', function () {
|
|||||||
console.error = consoleError;
|
console.error = consoleError;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('logs an info message', function (done) {
|
it('logs an info message', function (_t, done) {
|
||||||
console.log = function (msg) {
|
console.log = function (msg) {
|
||||||
assert.strictEqual(msg, 'sharp: progress');
|
assert.strictEqual(msg, 'sharp: progress');
|
||||||
done();
|
done();
|
||||||
@ -160,7 +161,7 @@ describe('libvips binaries', function () {
|
|||||||
libvips.log('progress');
|
libvips.log('progress');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('logs an error message', function (done) {
|
it('logs an error message', function (_t, done) {
|
||||||
console.error = function (msg) {
|
console.error = function (msg) {
|
||||||
assert.strictEqual(msg, 'sharp: Installation error: problem');
|
assert.strictEqual(msg, 'sharp: Installation error: problem');
|
||||||
done();
|
done();
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
describe('Linear adjustment', function () {
|
describe('Linear adjustment', function () {
|
||||||
@ -12,7 +13,7 @@ describe('Linear adjustment', function () {
|
|||||||
const a = 255 / (whitePoint - blackPoint);
|
const a = 255 / (whitePoint - blackPoint);
|
||||||
const b = -blackPoint * a;
|
const b = -blackPoint * a;
|
||||||
|
|
||||||
it('applies linear levels adjustment w/o alpha ch', function (done) {
|
it('applies linear levels adjustment w/o alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.linear(a, b)
|
.linear(a, b)
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
@ -21,7 +22,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies slope level adjustment w/o alpha ch', function (done) {
|
it('applies slope level adjustment w/o alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.linear(a)
|
.linear(a)
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
@ -30,7 +31,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies offset level adjustment w/o alpha ch', function (done) {
|
it('applies offset level adjustment w/o alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.linear(null, b)
|
.linear(null, b)
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
@ -39,7 +40,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies linear levels adjustment w alpha ch', function (done) {
|
it('applies linear levels adjustment w alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(240)
|
.resize(240)
|
||||||
.linear(a, b)
|
.linear(a, b)
|
||||||
@ -49,7 +50,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies linear levels adjustment to 16-bit w alpha ch', function (done) {
|
it('applies linear levels adjustment to 16-bit w alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.linear(a, b)
|
.linear(a, b)
|
||||||
.png({ compressionLevel: 0 })
|
.png({ compressionLevel: 0 })
|
||||||
@ -59,7 +60,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies slope level adjustment w alpha ch', function (done) {
|
it('applies slope level adjustment w alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(240)
|
.resize(240)
|
||||||
.linear(a)
|
.linear(a)
|
||||||
@ -69,7 +70,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies offset level adjustment w alpha ch', function (done) {
|
it('applies offset level adjustment w alpha ch', function (_t, done) {
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(240)
|
.resize(240)
|
||||||
.linear(null, b)
|
.linear(null, b)
|
||||||
@ -79,7 +80,7 @@ describe('Linear adjustment', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('per channel level adjustment', function (done) {
|
it('per channel level adjustment', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
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(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const exifReader = require('exif-reader');
|
const exifReader = require('exif-reader');
|
||||||
const icc = require('icc');
|
const icc = require('icc');
|
||||||
@ -12,7 +13,7 @@ const fixtures = require('../fixtures');
|
|||||||
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
||||||
|
|
||||||
describe('Image metadata', function () {
|
describe('Image metadata', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
sharp(fixtures.inputJpg).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
@ -34,7 +35,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG with EXIF/ICC', function (done) {
|
it('JPEG with EXIF/ICC', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) {
|
sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
@ -67,7 +68,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG with IPTC/XMP', function (done) {
|
it('JPEG with IPTC/XMP', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithIptcAndXmp).metadata(function (err, metadata) {
|
sharp(fixtures.inputJpgWithIptcAndXmp).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
// IPTC
|
// IPTC
|
||||||
@ -85,7 +86,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF', function (done) {
|
it('TIFF', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff).metadata(function (err, metadata) {
|
sharp(fixtures.inputTiff).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', metadata.format);
|
assert.strictEqual('tiff', metadata.format);
|
||||||
@ -112,7 +113,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multipage TIFF', function (done) {
|
it('Multipage TIFF', function (_t, done) {
|
||||||
sharp(fixtures.inputTiffMultipage).metadata(function (err, metadata) {
|
sharp(fixtures.inputTiffMultipage).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', metadata.format);
|
assert.strictEqual('tiff', metadata.format);
|
||||||
@ -135,7 +136,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function (done) {
|
it('PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', metadata.format);
|
assert.strictEqual('png', metadata.format);
|
||||||
@ -159,7 +160,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG with comment', function (done) {
|
it('PNG with comment', function (_t, done) {
|
||||||
sharp(fixtures.inputPngTestJoinChannel).metadata(function (err, metadata) {
|
sharp(fixtures.inputPngTestJoinChannel).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', metadata.format);
|
assert.strictEqual('png', metadata.format);
|
||||||
@ -184,7 +185,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Transparent PNG', function (done) {
|
it('Transparent PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', metadata.format);
|
assert.strictEqual('png', metadata.format);
|
||||||
@ -256,7 +257,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('WebP', function (done) {
|
it('WebP', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', metadata.format);
|
assert.strictEqual('webp', metadata.format);
|
||||||
@ -348,7 +349,7 @@ describe('Image metadata', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('GIF', function (done) {
|
it('GIF', function (_t, done) {
|
||||||
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('gif', metadata.format);
|
assert.strictEqual('gif', metadata.format);
|
||||||
@ -368,7 +369,7 @@ describe('Image metadata', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('GIF grey+alpha', function (done) {
|
it('GIF grey+alpha', function (_t, done) {
|
||||||
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) {
|
sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('gif', metadata.format);
|
assert.strictEqual('gif', metadata.format);
|
||||||
@ -456,7 +457,7 @@ describe('Image metadata', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('File in, Promise out', function (done) {
|
it('File in, Promise out', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).metadata().then(function (metadata) {
|
sharp(fixtures.inputJpg).metadata().then(function (metadata) {
|
||||||
assert.strictEqual('jpeg', metadata.format);
|
assert.strictEqual('jpeg', metadata.format);
|
||||||
assert.strictEqual('undefined', typeof metadata.size);
|
assert.strictEqual('undefined', typeof metadata.size);
|
||||||
@ -489,7 +490,7 @@ describe('Image metadata', function () {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Invalid stream in, callback out', (done) => {
|
it('Invalid stream in, callback out', (_t, done) => {
|
||||||
fs.createReadStream(__filename).pipe(
|
fs.createReadStream(__filename).pipe(
|
||||||
sharp().metadata((err) => {
|
sharp().metadata((err) => {
|
||||||
assert.strictEqual(err.message, 'Input buffer contains unsupported image format');
|
assert.strictEqual(err.message, 'Input buffer contains unsupported image format');
|
||||||
@ -500,7 +501,7 @@ describe('Image metadata', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream in, Promise out', function (done) {
|
it('Stream in, Promise out', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp();
|
const pipeline = sharp();
|
||||||
pipeline.metadata().then(function (metadata) {
|
pipeline.metadata().then(function (metadata) {
|
||||||
@ -520,7 +521,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('undefined', typeof metadata.exif);
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
assert.strictEqual('undefined', typeof metadata.icc);
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(_t, done);
|
||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -538,7 +539,7 @@ describe('Image metadata', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream in, finish event fires before metadata is requested', (done) => {
|
it('Stream in, finish event fires before metadata is requested', (_t, done) => {
|
||||||
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
||||||
const image1 = sharp({ create }).png().pipe(sharp());
|
const image1 = sharp({ create }).png().pipe(sharp());
|
||||||
const image2 = sharp({ create }).png().pipe(sharp());
|
const image2 = sharp({ create }).png().pipe(sharp());
|
||||||
@ -551,7 +552,7 @@ describe('Image metadata', function () {
|
|||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream', function (done) {
|
it('Stream', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().metadata(function (err, metadata) {
|
const pipeline = sharp().metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -575,7 +576,7 @@ describe('Image metadata', function () {
|
|||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Resize to half width using metadata', function (done) {
|
it('Resize to half width using metadata', function (_t, done) {
|
||||||
const image = sharp(fixtures.inputJpg);
|
const image = sharp(fixtures.inputJpg);
|
||||||
image.metadata(function (err, metadata) {
|
image.metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -604,7 +605,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keep EXIF metadata and add sRGB profile after a resize', function (done) {
|
it('Keep EXIF metadata and add sRGB profile after a resize', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
@ -724,7 +725,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual(undefined, metadata.icc);
|
assert.strictEqual(undefined, metadata.icc);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Apply CMYK output ICC profile', function (done) {
|
it('Apply CMYK output ICC profile', function (_t, done) {
|
||||||
const output = fixtures.path('output.icc-cmyk.jpg');
|
const output = fixtures.path('output.icc-cmyk.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(64)
|
.resize(64)
|
||||||
@ -749,7 +750,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Apply custom output ICC profile', function (done) {
|
it('Apply custom output ICC profile', function (_t, done) {
|
||||||
const output = fixtures.path('output.hilutite.jpg');
|
const output = fixtures.path('output.hilutite.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(64)
|
.resize(64)
|
||||||
@ -789,7 +790,7 @@ describe('Image metadata', function () {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Remove EXIF metadata after a resize', function (done) {
|
it('Remove EXIF metadata after a resize', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
@ -805,7 +806,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Remove metadata from PNG output', function (done) {
|
it('Remove metadata from PNG output', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
@ -992,7 +993,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual(description, 'sP3C');
|
assert.strictEqual(description, 'sP3C');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('File input with corrupt header fails gracefully', function (done) {
|
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.metadata(function (err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -1001,7 +1002,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Buffer input with corrupt header fails gracefully', function (done) {
|
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||||
.metadata(function (err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -1010,7 +1011,7 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Unsupported lossless JPEG passes underlying error message', function (done) {
|
it('Unsupported lossless JPEG passes underlying error message', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgLossless)
|
sharp(fixtures.inputJpgLossless)
|
||||||
.metadata(function (err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Negate', function () {
|
describe('Negate', function () {
|
||||||
it('negate (jpeg)', function (done) {
|
it('negate (jpeg)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -20,7 +21,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (png)', function (done) {
|
it('negate (png)', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -33,7 +34,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (png, trans)', function (done) {
|
it('negate (png, trans)', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -46,7 +47,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (png, alpha)', function (done) {
|
it('negate (png, alpha)', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -59,7 +60,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (webp)', function (done) {
|
it('negate (webp)', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -72,7 +73,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (webp, trans)', function (done) {
|
it('negate (webp, trans)', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPWithTransparency)
|
sharp(fixtures.inputWebPWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate()
|
.negate()
|
||||||
@ -85,7 +86,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (true)', function (done) {
|
it('negate (true)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate(true)
|
.negate(true)
|
||||||
@ -98,7 +99,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate (false)', function (done) {
|
it('negate (false)', function (_t, done) {
|
||||||
const output = fixtures.path('output.unmodified-by-negate.png');
|
const output = fixtures.path('output.unmodified-by-negate.png');
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.negate(false)
|
.negate(false)
|
||||||
@ -109,7 +110,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate ({alpha: true})', function (done) {
|
it('negate ({alpha: true})', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: true })
|
.negate({ alpha: true })
|
||||||
@ -122,7 +123,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate non-alpha channels (png)', function (done) {
|
it('negate non-alpha channels (png)', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
@ -135,7 +136,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate non-alpha channels (png, trans)', function (done) {
|
it('negate non-alpha channels (png, trans)', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
@ -148,7 +149,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate non-alpha channels (png, alpha)', function (done) {
|
it('negate non-alpha channels (png, alpha)', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
@ -161,7 +162,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate non-alpha channels (webp)', function (done) {
|
it('negate non-alpha channels (webp)', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
@ -174,7 +175,7 @@ describe('Negate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('negate non-alpha channels (webp, trans)', function (done) {
|
it('negate non-alpha channels (webp, trans)', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPWithTransparency)
|
sharp(fixtures.inputWebPWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Gaussian noise', function () {
|
describe('Gaussian noise', function () {
|
||||||
it('generate single-channel gaussian noise', function (done) {
|
it('generate single-channel gaussian noise', function (_t, done) {
|
||||||
const output = fixtures.path('output.noise-1-channel.png');
|
const output = fixtures.path('output.noise-1-channel.png');
|
||||||
const noise = sharp({
|
const noise = sharp({
|
||||||
create: {
|
create: {
|
||||||
@ -36,7 +37,7 @@ describe('Gaussian noise', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generate 3-channels gaussian noise', function (done) {
|
it('generate 3-channels gaussian noise', function (_t, done) {
|
||||||
const output = fixtures.path('output.noise-3-channels.png');
|
const output = fixtures.path('output.noise-3-channels.png');
|
||||||
const noise = sharp({
|
const noise = sharp({
|
||||||
create: {
|
create: {
|
||||||
@ -65,7 +66,7 @@ describe('Gaussian noise', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('overlay 3-channels gaussian noise over image', function (done) {
|
it('overlay 3-channels gaussian noise over image', function (_t, done) {
|
||||||
const output = fixtures.path('output.noise-image.jpg');
|
const output = fixtures.path('output.noise-image.jpg');
|
||||||
const noise = sharp({
|
const noise = sharp({
|
||||||
create: {
|
create: {
|
||||||
@ -110,7 +111,7 @@ describe('Gaussian noise', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('overlay strong single-channel (sRGB) gaussian noise with 25% transparency over transparent png image', function (done) {
|
it('overlay strong single-channel (sRGB) gaussian noise with 25% transparency over transparent png image', function (_t, done) {
|
||||||
const output = fixtures.path('output.noise-image-transparent.png');
|
const output = fixtures.path('output.noise-image-transparent.png');
|
||||||
const width = 320;
|
const width = 320;
|
||||||
const height = 240;
|
const height = 240;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -18,7 +19,7 @@ const assertNormalized = function (data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('Normalization', function () {
|
describe('Normalization', function () {
|
||||||
it('spreads rgb image values between 0 and 255', function (done) {
|
it('spreads rgb image values between 0 and 255', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.normalise()
|
.normalise()
|
||||||
.raw()
|
.raw()
|
||||||
@ -29,7 +30,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('spreads grayscaled image values between 0 and 255', function (done) {
|
it('spreads grayscaled image values between 0 and 255', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.normalize()
|
.normalize()
|
||||||
@ -41,7 +42,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stretches greyscale images with alpha channel', function (done) {
|
it('stretches greyscale images with alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.normalise()
|
.normalise()
|
||||||
.raw()
|
.raw()
|
||||||
@ -52,7 +53,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps an existing alpha channel', function (done) {
|
it('keeps an existing alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(8, 8)
|
.resize(8, 8)
|
||||||
.normalize()
|
.normalize()
|
||||||
@ -68,7 +69,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps the alpha channel of greyscale images intact', function (done) {
|
it('keeps the alpha channel of greyscale images intact', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(8, 8)
|
.resize(8, 8)
|
||||||
.normalise()
|
.normalise()
|
||||||
@ -84,7 +85,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not alter images with only one color', function (done) {
|
it('does not alter images with only one color', function (_t, done) {
|
||||||
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
const output = fixtures.path('output.unmodified-png-with-one-color.png');
|
||||||
sharp(fixtures.inputPngWithOneColor)
|
sharp(fixtures.inputPngWithOneColor)
|
||||||
.normalize()
|
.normalize()
|
||||||
@ -95,7 +96,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with 16-bit RGBA images', function (done) {
|
it('works with 16-bit RGBA images', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.normalise()
|
.normalise()
|
||||||
.raw()
|
.raw()
|
||||||
@ -106,7 +107,7 @@ describe('Normalization', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle luminance range', function (done) {
|
it('should handle luminance range', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.normalise({ lower: 10, upper: 70 })
|
.normalise({ lower: 10, upper: 70 })
|
||||||
.raw()
|
.raw()
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -20,7 +21,7 @@ describe('PNG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('default compressionLevel generates smaller file than compressionLevel=0', function (done) {
|
it('default compressionLevel generates smaller file than compressionLevel=0', function (_t, done) {
|
||||||
// First generate with default compressionLevel
|
// First generate with default compressionLevel
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -43,7 +44,7 @@ describe('PNG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('without adaptiveFiltering generates smaller file', function (done) {
|
it('without adaptiveFiltering generates smaller file', function (_t, done) {
|
||||||
// First generate with adaptive filtering
|
// First generate with adaptive filtering
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -78,7 +79,7 @@ describe('PNG', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Progressive PNG image', function (done) {
|
it('Progressive PNG image', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.png({ progressive: false })
|
.png({ progressive: false })
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -82,7 +83,7 @@ describe('Raw pixel data', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RGB', function (done) {
|
it('RGB', function (_t, done) {
|
||||||
// Convert to raw pixel data
|
// Convert to raw pixel data
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(256)
|
.resize(256)
|
||||||
@ -111,7 +112,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RGBA', function (done) {
|
it('RGBA', function (_t, done) {
|
||||||
// Convert to raw pixel data
|
// Convert to raw pixel data
|
||||||
sharp(fixtures.inputPngOverlayLayer1)
|
sharp(fixtures.inputPngOverlayLayer1)
|
||||||
.resize(256)
|
.resize(256)
|
||||||
@ -140,7 +141,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('RGBA premultiplied', function (done) {
|
it('RGBA premultiplied', function (_t, done) {
|
||||||
// Convert to raw pixel data
|
// Convert to raw pixel data
|
||||||
sharp(fixtures.inputPngSolidAlpha)
|
sharp(fixtures.inputPngSolidAlpha)
|
||||||
.resize(256)
|
.resize(256)
|
||||||
@ -186,7 +187,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG to raw Stream and back again', function (done) {
|
it('JPEG to raw Stream and back again', function (_t, done) {
|
||||||
const width = 32;
|
const width = 32;
|
||||||
const height = 24;
|
const height = 24;
|
||||||
const writable = sharp({
|
const writable = sharp({
|
||||||
@ -213,7 +214,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Output raw, uncompressed image data', function () {
|
describe('Output raw, uncompressed image data', function () {
|
||||||
it('1 channel greyscale image', function (done) {
|
it('1 channel greyscale image', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
@ -230,7 +231,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('3 channel colour image without transparency', function (done) {
|
it('3 channel colour image without transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.toFormat('raw')
|
.toFormat('raw')
|
||||||
@ -245,7 +246,7 @@ describe('Raw pixel data', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('4 channel colour image with transparency', function (done) {
|
it('4 channel colour image with transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(32, 24)
|
.resize(32, 24)
|
||||||
.toFormat(sharp.format.raw)
|
.toFormat(sharp.format.raw)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -13,7 +14,7 @@ const sepia = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
describe('Recomb', function () {
|
describe('Recomb', function () {
|
||||||
it('applies a sepia filter using recomb', function (done) {
|
it('applies a sepia filter using recomb', function (_t, done) {
|
||||||
const output = fixtures.path('output.recomb-sepia.jpg');
|
const output = fixtures.path('output.recomb-sepia.jpg');
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.recomb(sepia)
|
.recomb(sepia)
|
||||||
@ -31,7 +32,7 @@ describe('Recomb', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies a sepia filter using recomb to an PNG with Alpha', function (done) {
|
it('applies a sepia filter using recomb to an PNG with Alpha', function (_t, done) {
|
||||||
const output = fixtures.path('output.recomb-sepia.png');
|
const output = fixtures.path('output.recomb-sepia.png');
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.recomb(sepia)
|
.recomb(sepia)
|
||||||
@ -63,7 +64,7 @@ describe('Recomb', function () {
|
|||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies a different sepia filter using recomb', function (done) {
|
it('applies a different sepia filter using recomb', function (_t, done) {
|
||||||
const output = fixtures.path('output.recomb-sepia2.jpg');
|
const output = fixtures.path('output.recomb-sepia2.jpg');
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
.recomb([
|
.recomb([
|
||||||
@ -84,7 +85,7 @@ describe('Recomb', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('increases the saturation of the image', function (done) {
|
it('increases the saturation of the image', function (_t, done) {
|
||||||
const saturationLevel = 1;
|
const saturationLevel = 1;
|
||||||
const output = fixtures.path('output.recomb-saturation.jpg');
|
const output = fixtures.path('output.recomb-saturation.jpg');
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif1)
|
sharp(fixtures.inputJpgWithLandscapeExif1)
|
||||||
@ -119,7 +120,7 @@ describe('Recomb', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies opacity 30% to the image', function (done) {
|
it('applies opacity 30% to the image', function (_t, done) {
|
||||||
const output = fixtures.path('output.recomb-opacity.png');
|
const output = fixtures.path('output.recomb-opacity.png');
|
||||||
sharp(fixtures.inputPngWithTransparent)
|
sharp(fixtures.inputPngWithTransparent)
|
||||||
.recomb([
|
.recomb([
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Resize fit=contain', function () {
|
describe('Resize fit=contain', function () {
|
||||||
it('Allows specifying the position as a string', function (done) {
|
it('Allows specifying the position as a string', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240, {
|
.resize(320, 240, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -22,7 +23,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG within PNG, no alpha channel', function (done) {
|
it('JPEG within PNG, no alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240, { fit: 'contain' })
|
.resize(320, 240, { fit: 'contain' })
|
||||||
.png()
|
.png()
|
||||||
@ -37,7 +38,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG within WebP, to include alpha channel', function (done) {
|
it('JPEG within WebP, to include alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240, {
|
.resize(320, 240, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -55,7 +56,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG with alpha channel', function (done) {
|
it('PNG with alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(50, 50, { fit: 'contain' })
|
.resize(50, 50, { fit: 'contain' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -69,7 +70,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel', function (done) {
|
it('16-bit PNG with alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 16, { fit: 'contain' })
|
.resize(32, 16, { fit: 'contain' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -83,7 +84,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel onto RGBA', function (done) {
|
it('16-bit PNG with alpha channel onto RGBA', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 16, {
|
.resize(32, 16, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -100,7 +101,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG with 2 channels', function (done) {
|
it('PNG with 2 channels', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(32, 16, {
|
.resize(32, 16, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -117,7 +118,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF in LAB colourspace onto RGBA background', function (done) {
|
it('TIFF in LAB colourspace onto RGBA background', function (_t, done) {
|
||||||
sharp(fixtures.inputTiffCielab)
|
sharp(fixtures.inputTiffCielab)
|
||||||
.resize(64, 128, {
|
.resize(64, 128, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -135,7 +136,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Enlarge', function (done) {
|
it('Enlarge', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithOneColor)
|
sharp(fixtures.inputPngWithOneColor)
|
||||||
.resize(320, 240, { fit: 'contain' })
|
.resize(320, 240, { fit: 'contain' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -150,7 +151,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated WebP', function () {
|
describe('Animated WebP', function () {
|
||||||
it('Width only', function (done) {
|
it('Width only', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(320, 240, {
|
.resize(320, 240, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -167,7 +168,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Height only', function (done) {
|
it('Height only', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(240, 320, {
|
.resize(240, 320, {
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
@ -193,7 +194,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal top', function (done) {
|
it('Position horizontal top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -211,7 +212,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal right top', function (done) {
|
it('Position horizontal right top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -229,7 +230,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal right', function (done) {
|
it('Position horizontal right', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -247,7 +248,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal right bottom', function (done) {
|
it('Position horizontal right bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -265,7 +266,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal bottom', function (done) {
|
it('Position horizontal bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -283,7 +284,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal left bottom', function (done) {
|
it('Position horizontal left bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -301,7 +302,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal left', function (done) {
|
it('Position horizontal left', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -319,7 +320,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal left top', function (done) {
|
it('Position horizontal left top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -337,7 +338,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal north', function (done) {
|
it('Position horizontal north', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -355,7 +356,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal northeast', function (done) {
|
it('Position horizontal northeast', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -373,7 +374,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal east', function (done) {
|
it('Position horizontal east', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -391,7 +392,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal southeast', function (done) {
|
it('Position horizontal southeast', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -409,7 +410,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal south', function (done) {
|
it('Position horizontal south', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -427,7 +428,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal southwest', function (done) {
|
it('Position horizontal southwest', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -445,7 +446,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal west', function (done) {
|
it('Position horizontal west', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -463,7 +464,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal northwest', function (done) {
|
it('Position horizontal northwest', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -481,7 +482,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position horizontal center', function (done) {
|
it('Position horizontal center', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 100, {
|
.resize(200, 100, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -499,7 +500,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical top', function (done) {
|
it('Position vertical top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -517,7 +518,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical right top', function (done) {
|
it('Position vertical right top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -535,7 +536,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical right', function (done) {
|
it('Position vertical right', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -553,7 +554,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical right bottom', function (done) {
|
it('Position vertical right bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -571,7 +572,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical bottom', function (done) {
|
it('Position vertical bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -589,7 +590,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical left bottom', function (done) {
|
it('Position vertical left bottom', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -607,7 +608,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical left', function (done) {
|
it('Position vertical left', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -625,7 +626,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical left top', function (done) {
|
it('Position vertical left top', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -643,7 +644,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical north', function (done) {
|
it('Position vertical north', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -661,7 +662,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical northeast', function (done) {
|
it('Position vertical northeast', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -679,7 +680,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical east', function (done) {
|
it('Position vertical east', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -697,7 +698,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical southeast', function (done) {
|
it('Position vertical southeast', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -715,7 +716,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical south', function (done) {
|
it('Position vertical south', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -733,7 +734,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical southwest', function (done) {
|
it('Position vertical southwest', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -751,7 +752,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical west', function (done) {
|
it('Position vertical west', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -769,7 +770,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical northwest', function (done) {
|
it('Position vertical northwest', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
@ -787,7 +788,7 @@ describe('Resize fit=contain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Position vertical center', function (done) {
|
it('Position vertical center', function (_t, done) {
|
||||||
sharp(fixtures.inputPngEmbed)
|
sharp(fixtures.inputPngEmbed)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.contain,
|
fit: sharp.fit.contain,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -200,7 +201,7 @@ describe('Resize fit=cover', function () {
|
|||||||
fixture: 'gravity-west.jpg'
|
fixture: 'gravity-west.jpg'
|
||||||
}
|
}
|
||||||
].forEach(function (settings) {
|
].forEach(function (settings) {
|
||||||
it(settings.name, function (done) {
|
it(settings.name, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(settings.width, settings.height, {
|
.resize(settings.width, settings.height, {
|
||||||
fit: sharp.fit.cover,
|
fit: sharp.fit.cover,
|
||||||
@ -215,7 +216,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Allows specifying the gravity as a string', function (done) {
|
it('Allows specifying the gravity as a string', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320, {
|
.resize(80, 320, {
|
||||||
fit: sharp.fit.cover,
|
fit: sharp.fit.cover,
|
||||||
@ -271,7 +272,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated WebP', function () {
|
describe('Animated WebP', function () {
|
||||||
it('Width only', function (done) {
|
it('Width only', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(80, 320, { fit: sharp.fit.cover })
|
.resize(80, 320, { fit: sharp.fit.cover })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -282,7 +283,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Height only', function (done) {
|
it('Height only', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
.resize(320, 80, { fit: sharp.fit.cover })
|
.resize(320, 80, { fit: sharp.fit.cover })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -295,7 +296,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Entropy-based strategy', function () {
|
describe('Entropy-based strategy', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320, {
|
.resize(80, 320, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -313,7 +314,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function (done) {
|
it('PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80, {
|
.resize(320, 80, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -331,7 +332,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports the strategy passed as a string', function (done) {
|
it('supports the strategy passed as a string', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80, {
|
.resize(320, 80, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -363,7 +364,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Attention strategy', function () {
|
describe('Attention strategy', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(80, 320, {
|
.resize(80, 320, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -383,7 +384,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG', function (done) {
|
it('PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80, {
|
.resize(320, 80, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -403,7 +404,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('WebP', function (done) {
|
it('WebP', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 80, {
|
.resize(320, 80, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
@ -423,7 +424,7 @@ describe('Resize fit=cover', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports the strategy passed as a string', function (done) {
|
it('supports the strategy passed as a string', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 80, {
|
.resize(320, 80, {
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Resize dimensions', function () {
|
describe('Resize dimensions', function () {
|
||||||
it('Exact crop', function (done) {
|
it('Exact crop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
@ -18,7 +19,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fixed width', function (done) {
|
it('Fixed width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).resize(320).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).resize(320).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
@ -29,7 +30,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Fixed height', function (done) {
|
it('Fixed height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
@ -40,7 +41,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Identity transform', function (done) {
|
it('Identity transform', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
@ -51,7 +52,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Upscale', function (done) {
|
it('Upscale', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(3000)
|
.resize(3000)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -100,7 +101,7 @@ describe('Resize dimensions', function () {
|
|||||||
}, /Expected positive integer for height but received 1.5 of type number/);
|
}, /Expected positive integer for height but received 1.5 of type number/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid width - too large', function (done) {
|
it('Invalid width - too large', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(0x4000, 1)
|
.resize(0x4000, 1)
|
||||||
.webp()
|
.webp()
|
||||||
@ -111,7 +112,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid height - too large', function (done) {
|
it('Invalid height - too large', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(1, 0x4000)
|
.resize(1, 0x4000)
|
||||||
.webp()
|
.webp()
|
||||||
@ -122,7 +123,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Webp resize then extract large image', function (done) {
|
it('Webp resize then extract large image', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(0x4000, 0x4000)
|
.resize(0x4000, 0x4000)
|
||||||
.extract({ top: 0x2000, left: 0x2000, width: 256, height: 256 })
|
.extract({ top: 0x2000, left: 0x2000, width: 256, height: 256 })
|
||||||
@ -136,7 +137,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) {
|
it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(1080, 607)
|
.resize(1080, 607)
|
||||||
.webp()
|
.webp()
|
||||||
@ -157,7 +158,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', function (done) {
|
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(1920, 1280)
|
.resize(1920, 1280)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -176,7 +177,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF embed known to cause rounding errors', function (done) {
|
it('TIFF embed known to cause rounding errors', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(240, 320, { fit: sharp.fit.contain })
|
.resize(240, 320, { fit: sharp.fit.contain })
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -190,7 +191,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF known to cause rounding errors', function (done) {
|
it('TIFF known to cause rounding errors', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(240, 320)
|
.resize(240, 320)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -204,7 +205,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=inside, portrait', function (done) {
|
it('fit=inside, portrait', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 320, { fit: sharp.fit.inside })
|
.resize(320, 320, { fit: sharp.fit.inside })
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -218,7 +219,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=outside, portrait', function (done) {
|
it('fit=outside, portrait', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 320, { fit: sharp.fit.outside })
|
.resize(320, 320, { fit: sharp.fit.outside })
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -232,7 +233,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=inside, landscape', function (done) {
|
it('fit=inside, landscape', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 320, { fit: sharp.fit.inside })
|
.resize(320, 320, { fit: sharp.fit.inside })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -245,7 +246,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=outside, landscape', function (done) {
|
it('fit=outside, landscape', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 320, { fit: sharp.fit.outside })
|
.resize(320, 320, { fit: sharp.fit.outside })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -258,7 +259,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=inside, provide only one dimension', function (done) {
|
it('fit=inside, provide only one dimension', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 320,
|
width: 320,
|
||||||
@ -274,7 +275,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=outside, provide only one dimension', function (done) {
|
it('fit=outside, provide only one dimension', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 320,
|
width: 320,
|
||||||
@ -290,7 +291,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not enlarge when input width is already less than output width', function (done) {
|
it('Do not enlarge when input width is already less than output width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 2800,
|
width: 2800,
|
||||||
@ -306,7 +307,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not enlarge when input height is already less than output height', function (done) {
|
it('Do not enlarge when input height is already less than output height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
height: 2300,
|
height: 2300,
|
||||||
@ -322,7 +323,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do crop when fit = cover and withoutEnlargement = true and width >= outputWidth, and height < outputHeight', function (done) {
|
it('Do crop when fit = cover and withoutEnlargement = true and width >= outputWidth, and height < outputHeight', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 3000,
|
width: 3000,
|
||||||
@ -339,7 +340,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do crop when fit = cover and withoutEnlargement = true and width < outputWidth, and height >= outputHeight', function (done) {
|
it('Do crop when fit = cover and withoutEnlargement = true and width < outputWidth, and height >= outputHeight', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 1500,
|
width: 1500,
|
||||||
@ -356,7 +357,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do enlarge when input width is less than output width', function (done) {
|
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 2800,
|
width: 2800,
|
||||||
@ -372,7 +373,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do enlarge when input width is less than output width', function (done) {
|
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 2800,
|
width: 2800,
|
||||||
@ -388,7 +389,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do enlarge when input height is less than output height', function (done) {
|
it('Do enlarge when input height is less than output height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
height: 2300,
|
height: 2300,
|
||||||
@ -404,7 +405,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do enlarge when input width is less than output width', function (done) {
|
it('Do enlarge when input width is less than output width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 2800,
|
width: 2800,
|
||||||
@ -420,7 +421,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not resize when both withoutEnlargement and withoutReduction are true', function (done) {
|
it('Do not resize when both withoutEnlargement and withoutReduction are true', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 320, { fit: 'fill', withoutEnlargement: true, withoutReduction: true })
|
.resize(320, 320, { fit: 'fill', withoutEnlargement: true, withoutReduction: true })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -433,7 +434,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not reduce size when fit = outside and withoutReduction are true and height > outputHeight and width > outputWidth', function (done) {
|
it('Do not reduce size when fit = outside and withoutReduction are true and height > outputHeight and width > outputWidth', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 320, { fit: 'outside', withoutReduction: true })
|
.resize(320, 320, { fit: 'outside', withoutReduction: true })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -446,7 +447,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do resize when fit = outside and withoutReduction are true and input height > height and input width > width ', function (done) {
|
it('Do resize when fit = outside and withoutReduction are true and input height > height and input width > width ', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(3000, 3000, { fit: 'outside', withoutReduction: true })
|
.resize(3000, 3000, { fit: 'outside', withoutReduction: true })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -459,7 +460,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, downscale width and height', function (done) {
|
it('fit=fill, downscale width and height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 320, { fit: 'fill' })
|
.resize(320, 320, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -472,7 +473,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, downscale width', function (done) {
|
it('fit=fill, downscale width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
width: 320,
|
width: 320,
|
||||||
@ -488,7 +489,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, downscale height', function (done) {
|
it('fit=fill, downscale height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize({
|
.resize({
|
||||||
height: 320,
|
height: 320,
|
||||||
@ -504,7 +505,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, upscale width and height', function (done) {
|
it('fit=fill, upscale width and height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(3000, 3000, { fit: 'fill' })
|
.resize(3000, 3000, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -517,7 +518,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, upscale width', function (done) {
|
it('fit=fill, upscale width', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(3000, null, { fit: 'fill' })
|
.resize(3000, null, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -530,7 +531,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, upscale height', function (done) {
|
it('fit=fill, upscale height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(null, 3000, { fit: 'fill' })
|
.resize(null, 3000, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -543,7 +544,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, downscale width, upscale height', function (done) {
|
it('fit=fill, downscale width, upscale height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 3000, { fit: 'fill' })
|
.resize(320, 3000, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -556,7 +557,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, upscale width, downscale height', function (done) {
|
it('fit=fill, upscale width, downscale height', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(3000, 320, { fit: 'fill' })
|
.resize(3000, 320, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -569,7 +570,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fit=fill, identity transform', function (done) {
|
it('fit=fill, identity transform', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(null, null, { fit: 'fill' })
|
.resize(null, null, { fit: 'fill' })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -582,7 +583,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dimensions that result in differing even shrinks on each axis', function (done) {
|
it('Dimensions that result in differing even shrinks on each axis', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(645, 399)
|
.resize(645, 399)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -600,7 +601,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dimensions that result in differing odd shrinks on each axis', function (done) {
|
it('Dimensions that result in differing odd shrinks on each axis', function (_t, done) {
|
||||||
return sharp(fixtures.inputJpg)
|
return sharp(fixtures.inputJpg)
|
||||||
.resize(600, 399)
|
.resize(600, 399)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -622,7 +623,7 @@ describe('Resize dimensions', function () {
|
|||||||
true,
|
true,
|
||||||
false
|
false
|
||||||
].forEach(function (value) {
|
].forEach(function (value) {
|
||||||
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (done) {
|
it(`fastShrinkOnLoad: ${value} does not causes image shifts`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpgCenteredImage)
|
sharp(fixtures.inputJpgCenteredImage)
|
||||||
.resize(9, 8, { fastShrinkOnLoad: value })
|
.resize(9, 8, { fastShrinkOnLoad: value })
|
||||||
.png()
|
.png()
|
||||||
@ -642,7 +643,7 @@ describe('Resize dimensions', function () {
|
|||||||
sharp.kernel.lanczos2,
|
sharp.kernel.lanczos2,
|
||||||
sharp.kernel.lanczos3
|
sharp.kernel.lanczos3
|
||||||
].forEach(function (kernel) {
|
].forEach(function (kernel) {
|
||||||
it(`kernel ${kernel}`, function (done) {
|
it(`kernel ${kernel}`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, null, { kernel })
|
.resize(320, null, { kernel })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -654,7 +655,7 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nearest upsampling with integral factor', function (done) {
|
it('nearest upsampling with integral factor', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff8BitDepth)
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
.resize(210, 210, { kernel: 'nearest' })
|
.resize(210, 210, { kernel: 'nearest' })
|
||||||
.png()
|
.png()
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -15,7 +16,7 @@ describe('Rotation', function () {
|
|||||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
||||||
const input = fixtures[`inputJpgWith${orientation}Exif${exifTag}`];
|
const input = fixtures[`inputJpgWith${orientation}Exif${exifTag}`];
|
||||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}-out.jpg`);
|
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}-out.jpg`);
|
||||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, function (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, function (_t, done) {
|
||||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||||
|
|
||||||
const img = sharp(input, options);
|
const img = sharp(input, options);
|
||||||
@ -29,7 +30,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, function (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, function (_t, done) {
|
||||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [320, 240] : [320, 427];
|
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [320, 240] : [320, 427];
|
||||||
|
|
||||||
const img = sharp(input, options);
|
const img = sharp(input, options);
|
||||||
@ -45,7 +46,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (rotateMethod !== 'constructor') {
|
if (rotateMethod !== 'constructor') {
|
||||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, function (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, function (_t, done) {
|
||||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape'
|
const [expectedWidth, expectedHeight] = orientation === 'Landscape'
|
||||||
? (exifTag < 5) ? [320, 240] : [320, 240]
|
? (exifTag < 5) ? [320, 240] : [320, 240]
|
||||||
: [320, 427];
|
: [320, 427];
|
||||||
@ -67,7 +68,7 @@ describe('Rotation', function () {
|
|||||||
[90, 180, 270, 45].forEach(function (angle) {
|
[90, 180, 270, 45].forEach(function (angle) {
|
||||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_rotate${angle}-out.jpg`);
|
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 (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||||
const [width, height] = (angle === 45 ? [742, 742] : [inputWidth, inputHeight]).map((x) => doResize ? Math.floor(x / 1.875) : x);
|
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];
|
const [expectedWidth, expectedHeight] = angle % 180 === 0 ? [width, height] : [height, width];
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ describe('Rotation', function () {
|
|||||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||||
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
||||||
const flipFlopTestName = [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 (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
||||||
|
|
||||||
const img = sharp(input, options);
|
const img = sharp(input, options);
|
||||||
@ -115,7 +116,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 30 degrees with semi-transparent background', function (done) {
|
it('Rotate by 30 degrees with semi-transparent background', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.rotate(30, { background: { r: 255, g: 0, b: 0, alpha: 0.5 } })
|
.rotate(30, { background: { r: 255, g: 0, b: 0, alpha: 0.5 } })
|
||||||
@ -129,7 +130,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 30 degrees with solid background', function (done) {
|
it('Rotate by 30 degrees with solid background', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.rotate(30, { background: { r: 255, g: 0, b: 0 } })
|
.rotate(30, { background: { r: 255, g: 0, b: 0 } })
|
||||||
@ -142,7 +143,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 90 degrees, respecting output input size', function (done) {
|
it('Rotate by 90 degrees, respecting output input size', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -156,7 +157,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Resize then rotate by 30 degrees, respecting output input size', function (done) {
|
it('Resize then rotate by 30 degrees, respecting output input size', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.rotate(30)
|
.rotate(30)
|
||||||
@ -171,7 +172,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
[-3690, -450, -90, 90, 450, 3690].forEach(function (angle) {
|
[-3690, -450, -90, 90, 450, 3690].forEach(function (angle) {
|
||||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (done) {
|
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(240, info.width);
|
assert.strictEqual(240, info.width);
|
||||||
@ -182,7 +183,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) {
|
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) {
|
||||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (done) {
|
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(397, info.width);
|
assert.strictEqual(397, info.width);
|
||||||
@ -193,7 +194,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
[-3780, -540, 0, 180, 540, 3780].forEach(function (angle) {
|
[-3780, -540, 0, 180, 540, 3780].forEach(function (angle) {
|
||||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (done) {
|
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (_t, done) {
|
||||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
@ -203,7 +204,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (done) {
|
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(240, 240, { fit: sharp.fit.fill })
|
.resize(240, 240, { fit: sharp.fit.fill })
|
||||||
.rotate(270)
|
.rotate(270)
|
||||||
@ -220,7 +221,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 315 degrees, square output ignoring aspect ratio', function (done) {
|
it('Rotate by 315 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(240, 240, { fit: sharp.fit.fill })
|
.resize(240, 240, { fit: sharp.fit.fill })
|
||||||
.rotate(315)
|
.rotate(315)
|
||||||
@ -237,7 +238,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(270)
|
.rotate(270)
|
||||||
.resize(320, 240, { fit: sharp.fit.fill })
|
.resize(320, 240, { fit: sharp.fit.fill })
|
||||||
@ -254,7 +255,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithLandscapeExif8)
|
sharp(fixtures.inputJpgWithLandscapeExif8)
|
||||||
.resize(320, 240, { fit: sharp.fit.fill })
|
.resize(320, 240, { fit: sharp.fit.fill })
|
||||||
.rotate()
|
.rotate()
|
||||||
@ -271,7 +272,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', function (done) {
|
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240, { fit: sharp.fit.fill })
|
.resize(320, 240, { fit: sharp.fit.fill })
|
||||||
.rotate(30)
|
.rotate(30)
|
||||||
@ -288,7 +289,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag but do not rotate output', function (done) {
|
it('Input image has Orientation EXIF tag but do not rotate output', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
@ -306,7 +307,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (done) {
|
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
@ -319,7 +320,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Override EXIF Orientation tag metadata after auto-rotate', function (done) {
|
it('Override EXIF Orientation tag metadata after auto-rotate', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
@ -337,7 +338,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (done) {
|
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExifMirroring)
|
sharp(fixtures.inputJpgWithExifMirroring)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
@ -355,7 +356,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Attempt to auto-rotate using image that has no EXIF', function (done) {
|
it('Attempt to auto-rotate using image that has no EXIF', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
@ -366,7 +367,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Attempt to auto-rotate image format without EXIF support', function (done) {
|
it('Attempt to auto-rotate image format without EXIF support', function (_t, done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(320)
|
.resize(320)
|
||||||
@ -440,7 +441,7 @@ describe('Rotation', function () {
|
|||||||
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
|
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple rotate: last one wins (cardinal)', function (done) {
|
it('Multiple rotate: last one wins (cardinal)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(45)
|
.rotate(45)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
@ -452,7 +453,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple rotate: last one wins (non cardinal)', function (done) {
|
it('Multiple rotate: last one wins (non cardinal)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.rotate(45)
|
.rotate(45)
|
||||||
@ -464,7 +465,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flip - vertical', function (done) {
|
it('Flip - vertical', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip()
|
.flip()
|
||||||
@ -482,7 +483,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flop - horizontal', function (done) {
|
it('Flop - horizontal', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flop()
|
.flop()
|
||||||
@ -500,7 +501,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Flip and flop', function (done) {
|
it('Flip and flop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip()
|
.flip()
|
||||||
@ -514,7 +515,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Neither flip nor flop', function (done) {
|
it('Neither flip nor flop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
.flip(false)
|
.flip(false)
|
||||||
@ -528,7 +529,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Auto-rotate and flip', function (done) {
|
it('Auto-rotate and flip', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.flip()
|
.flip()
|
||||||
@ -542,7 +543,7 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Auto-rotate and flop', function (done) {
|
it('Auto-rotate and flop', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.rotate()
|
.rotate()
|
||||||
.flop()
|
.flop()
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Sharpen', function () {
|
describe('Sharpen', function () {
|
||||||
it('specific radius 10 (sigma 6)', function (done) {
|
it('specific radius 10 (sigma 6)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(6)
|
.sharpen(6)
|
||||||
@ -20,7 +21,7 @@ describe('Sharpen', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (done) {
|
it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(1.5, 0.5, 2.5)
|
.sharpen(1.5, 0.5, 2.5)
|
||||||
@ -33,7 +34,7 @@ describe('Sharpen', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('specific radius 5 (sigma 3.5) and levels 2, 4', function (done) {
|
it('specific radius 5 (sigma 3.5) and levels 2, 4', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(3.5, 2, 4)
|
.sharpen(3.5, 2, 4)
|
||||||
@ -46,7 +47,7 @@ describe('Sharpen', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sigma=3.5, m1=2, m2=4', (done) => {
|
it('sigma=3.5, m1=2, m2=4', (_t, done) => {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen({ sigma: 3.5, m1: 2, m2: 4 })
|
.sharpen({ sigma: 3.5, m1: 2, m2: 4 })
|
||||||
@ -54,7 +55,7 @@ describe('Sharpen', function () {
|
|||||||
.then(data => fixtures.assertSimilar(fixtures.expected('sharpen-5-2-4.jpg'), data, done));
|
.then(data => fixtures.assertSimilar(fixtures.expected('sharpen-5-2-4.jpg'), data, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sigma=3.5, m1=2, m2=4, x1=2, y2=5, y3=25', (done) => {
|
it('sigma=3.5, m1=2, m2=4, x1=2, y2=5, y3=25', (_t, done) => {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen({ sigma: 3.5, m1: 2, m2: 4, x1: 2, y2: 5, y3: 25 })
|
.sharpen({ sigma: 3.5, m1: 2, m2: 4, x1: 2, y2: 5, y3: 25 })
|
||||||
@ -63,7 +64,7 @@ describe('Sharpen', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
if (!process.env.SHARP_TEST_WITHOUT_CACHE) {
|
||||||
it('specific radius/levels with alpha channel', function (done) {
|
it('specific radius/levels with alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(5, 4, 8)
|
.sharpen(5, 4, 8)
|
||||||
@ -78,7 +79,7 @@ describe('Sharpen', function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('mild sharpen', function (done) {
|
it('mild sharpen', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen()
|
.sharpen()
|
||||||
@ -139,7 +140,7 @@ describe('Sharpen', function () {
|
|||||||
/Expected number between 0 and 1000000 for options\.y3 but received -1 of type number/
|
/Expected number between 0 and 1000000 for options\.y3 but received -1 of type number/
|
||||||
));
|
));
|
||||||
|
|
||||||
it('sharpened image is larger than non-sharpened', function (done) {
|
it('sharpened image is larger than non-sharpened', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.sharpen(false)
|
.sharpen(false)
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -20,7 +21,7 @@ function isInteger (val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('Image Stats', function () {
|
describe('Image Stats', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg).stats(function (err, stats) {
|
sharp(fixtures.inputJpg).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG without transparency', function (done) {
|
it('PNG without transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputPng).stats(function (err, stats) {
|
sharp(fixtures.inputPng).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG with transparency', function (done) {
|
it('PNG with transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency).stats(function (err, stats) {
|
sharp(fixtures.inputPngWithTransparency).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -198,7 +199,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PNG fully transparent', function (done) {
|
it('PNG fully transparent', function (_t, done) {
|
||||||
sharp(fixtures.inputPngCompleteTransparency).stats(function (err, stats) {
|
sharp(fixtures.inputPngCompleteTransparency).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -231,7 +232,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tiff', function (done) {
|
it('Tiff', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff).stats(function (err, stats) {
|
sharp(fixtures.inputTiff).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -264,7 +265,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('WebP', function (done) {
|
it('WebP', function (_t, done) {
|
||||||
sharp(fixtures.inputWebP).stats(function (err, stats) {
|
sharp(fixtures.inputWebP).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -329,7 +330,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('GIF', function (done) {
|
it('GIF', function (_t, done) {
|
||||||
sharp(fixtures.inputGif).stats(function (err, stats) {
|
sharp(fixtures.inputGif).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -394,7 +395,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Grayscale GIF with alpha', function (done) {
|
it('Grayscale GIF with alpha', function (_t, done) {
|
||||||
sharp(fixtures.inputGifGreyPlusAlpha).stats(function (err, stats) {
|
sharp(fixtures.inputGifGreyPlusAlpha).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@ -476,7 +477,7 @@ describe('Image Stats', function () {
|
|||||||
assert.strictEqual(sharpness, 0);
|
assert.strictEqual(sharpness, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream in, Callback out', function (done) {
|
it('Stream in, Callback out', function (_t, done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().stats(function (err, stats) {
|
const pipeline = sharp().stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -685,7 +686,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('File input with corrupt header fails gracefully', function (done) {
|
it('File input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.stats(function (err) {
|
.stats(function (err) {
|
||||||
assert(err.message.includes('Input file has corrupt header'));
|
assert(err.message.includes('Input file has corrupt header'));
|
||||||
@ -695,7 +696,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Stream input with corrupt header fails gracefully', function (done) {
|
it('Stream input with corrupt header fails gracefully', function (_t, done) {
|
||||||
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(
|
fs.createReadStream(fixtures.inputJpgWithCorruptHeader).pipe(
|
||||||
sharp()
|
sharp()
|
||||||
.stats(function (err) {
|
.stats(function (err) {
|
||||||
@ -729,7 +730,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Buffer input with corrupt header fails gracefully', function (done) {
|
it('Buffer input with corrupt header fails gracefully', function (_t, done) {
|
||||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||||
.stats(function (err) {
|
.stats(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -737,7 +738,7 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-existent file in, Promise out', function (done) {
|
it('Non-existent file in, Promise out', function (_t, done) {
|
||||||
sharp('fail').stats().then(function () {
|
sharp('fail').stats().then(function () {
|
||||||
throw new Error('Non-existent file');
|
throw new Error('Non-existent file');
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
|
|||||||
@ -2,13 +2,14 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('SVG input', function () {
|
describe('SVG input', function () {
|
||||||
it('Convert SVG to PNG at default 72DPI', function (done) {
|
it('Convert SVG to PNG at default 72DPI', function (_t, done) {
|
||||||
sharp(fixtures.inputSvg)
|
sharp(fixtures.inputSvg)
|
||||||
.resize(1024)
|
.resize(1024)
|
||||||
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
||||||
@ -29,7 +30,7 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG at 1200DPI', function (done) {
|
it('Convert SVG to PNG at 1200DPI', function (_t, done) {
|
||||||
sharp(fixtures.inputSvg, { density: 1200 })
|
sharp(fixtures.inputSvg, { density: 1200 })
|
||||||
.resize(1024)
|
.resize(1024)
|
||||||
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
.extract({ left: 290, top: 760, width: 40, height: 40 })
|
||||||
@ -50,7 +51,7 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG at DPI larger than 2400', function (done) {
|
it('Convert SVG to PNG at DPI larger than 2400', function (_t, done) {
|
||||||
const size = 1024;
|
const size = 1024;
|
||||||
sharp(fixtures.inputSvgSmallViewBox).metadata(function (err, metadata) {
|
sharp(fixtures.inputSvgSmallViewBox).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -75,7 +76,7 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG utilizing scale-on-load', function (done) {
|
it('Convert SVG to PNG utilizing scale-on-load', function (_t, done) {
|
||||||
const size = 1024;
|
const size = 1024;
|
||||||
sharp(fixtures.inputSvgSmallViewBox)
|
sharp(fixtures.inputSvgSmallViewBox)
|
||||||
.resize(size)
|
.resize(size)
|
||||||
@ -96,7 +97,7 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG at 14.4DPI', function (done) {
|
it('Convert SVG to PNG at 14.4DPI', function (_t, done) {
|
||||||
sharp(fixtures.inputSvg, { density: 14.4 })
|
sharp(fixtures.inputSvg, { density: 14.4 })
|
||||||
.toFormat('png')
|
.toFormat('png')
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -111,7 +112,7 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Convert SVG with embedded images to PNG, respecting dimensions, autoconvert to PNG', function (done) {
|
it('Convert SVG with embedded images to PNG, respecting dimensions, autoconvert to PNG', function (_t, done) {
|
||||||
sharp(fixtures.inputSvgWithEmbeddedImages)
|
sharp(fixtures.inputSvgWithEmbeddedImages)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -8,9 +9,7 @@ const fixtures = require('../fixtures');
|
|||||||
const { inRange } = require('../../lib/is');
|
const { inRange } = require('../../lib/is');
|
||||||
|
|
||||||
describe('Text to image', function () {
|
describe('Text to image', function () {
|
||||||
this.retries(3);
|
it('text with default values', async function (t) {
|
||||||
|
|
||||||
it('text with default values', async function () {
|
|
||||||
const output = fixtures.path('output.text-default.png');
|
const output = fixtures.path('output.text-default.png');
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
text: {
|
text: {
|
||||||
@ -18,7 +17,7 @@ describe('Text to image', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
const info = await text.png().toFile(output);
|
const info = await text.png().toFile(output);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -40,7 +39,7 @@ describe('Text to image', function () {
|
|||||||
assert.ok(info.textAutofitDpi > 0);
|
assert.ok(info.textAutofitDpi > 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with width and height', function (done) {
|
it('text with width and height', function (t, done) {
|
||||||
const output = fixtures.path('output.text-width-height.png');
|
const output = fixtures.path('output.text-width-height.png');
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
text: {
|
text: {
|
||||||
@ -50,7 +49,7 @@ describe('Text to image', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -63,7 +62,7 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with dpi', function (done) {
|
it('text with dpi', function (t, done) {
|
||||||
const output = fixtures.path('output.text-dpi.png');
|
const output = fixtures.path('output.text-dpi.png');
|
||||||
const dpi = 300;
|
const dpi = 300;
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
@ -73,7 +72,7 @@ describe('Text to image', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -86,7 +85,7 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with color and pango markup', function (done) {
|
it('text with color and pango markup', function (t, done) {
|
||||||
const output = fixtures.path('output.text-color-pango.png');
|
const output = fixtures.path('output.text-color-pango.png');
|
||||||
const dpi = 300;
|
const dpi = 300;
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
@ -97,7 +96,7 @@ describe('Text to image', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -113,7 +112,7 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with font', function (done) {
|
it('text with font', function (t, done) {
|
||||||
const output = fixtures.path('output.text-with-font.png');
|
const output = fixtures.path('output.text-with-font.png');
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
text: {
|
text: {
|
||||||
@ -122,7 +121,7 @@ describe('Text to image', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -134,7 +133,7 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with justify and composite', function (done) {
|
it('text with justify and composite', function (t, done) {
|
||||||
const output = fixtures.path('output.text-composite.png');
|
const output = fixtures.path('output.text-composite.png');
|
||||||
const width = 500;
|
const width = 500;
|
||||||
const dpi = 300;
|
const dpi = 300;
|
||||||
@ -166,7 +165,7 @@ describe('Text to image', function () {
|
|||||||
top: 250
|
top: 250
|
||||||
}]);
|
}]);
|
||||||
if (!sharp.versions.pango) {
|
if (!sharp.versions.pango) {
|
||||||
return this.skip();
|
return t.skip();
|
||||||
}
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Threshold', function () {
|
describe('Threshold', function () {
|
||||||
it('threshold 1 jpeg', function (done) {
|
it('threshold 1 jpeg', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(1)
|
.threshold(1)
|
||||||
@ -20,7 +21,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold 40 jpeg', function (done) {
|
it('threshold 40 jpeg', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(40)
|
.threshold(40)
|
||||||
@ -33,7 +34,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold 128', function (done) {
|
it('threshold 128', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128)
|
.threshold(128)
|
||||||
@ -46,7 +47,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold true (=128)', function (done) {
|
it('threshold true (=128)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(true)
|
.threshold(true)
|
||||||
@ -59,7 +60,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold false (=0)', function (done) {
|
it('threshold false (=0)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.threshold(false)
|
.threshold(false)
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
@ -68,7 +69,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold grayscale: true (=128)', function (done) {
|
it('threshold grayscale: true (=128)', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128, { grayscale: true })
|
.threshold(128, { grayscale: true })
|
||||||
@ -81,7 +82,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default jpeg', function (done) {
|
it('threshold default jpeg', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
@ -94,7 +95,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default png transparency', function (done) {
|
it('threshold default png transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
@ -107,7 +108,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default png alpha', function (done) {
|
it('threshold default png alpha', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithGreyAlpha)
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold()
|
.threshold()
|
||||||
@ -120,7 +121,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('threshold default webp transparency', function (done) {
|
it('threshold default webp transparency', function (_t, done) {
|
||||||
sharp(fixtures.inputWebPWithTransparency)
|
sharp(fixtures.inputWebPWithTransparency)
|
||||||
.threshold()
|
.threshold()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -130,7 +131,7 @@ describe('Threshold', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('color threshold', function (done) {
|
it('color threshold', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.threshold(128, { grayscale: false })
|
.threshold(128, { grayscale: false })
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -10,7 +11,7 @@ const fixtures = require('../fixtures');
|
|||||||
const outputTiff = fixtures.path('output.tiff');
|
const outputTiff = fixtures.path('output.tiff');
|
||||||
|
|
||||||
describe('TIFF', function () {
|
describe('TIFF', function () {
|
||||||
it('Load TIFF from Buffer', function (done) {
|
it('Load TIFF from Buffer', function (_t, done) {
|
||||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||||
sharp(inputTiffBuffer)
|
sharp(inputTiffBuffer)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -26,7 +27,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Load multi-page TIFF from file', function (done) {
|
it('Load multi-page TIFF from file', function (_t, done) {
|
||||||
sharp(fixtures.inputTiffMultipage) // defaults to page 0
|
sharp(fixtures.inputTiffMultipage) // defaults to page 0
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||||
@ -49,7 +50,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Load multi-page TIFF from Buffer', function (done) {
|
it('Load multi-page TIFF from Buffer', function (_t, done) {
|
||||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiffMultipage);
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiffMultipage);
|
||||||
sharp(inputTiffBuffer) // defaults to page 0
|
sharp(inputTiffBuffer) // defaults to page 0
|
||||||
.jpeg()
|
.jpeg()
|
||||||
@ -73,7 +74,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Save TIFF to Buffer', function (done) {
|
it('Save TIFF to Buffer', function (_t, done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -114,7 +115,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Not squashing TIFF to a bit depth of 1 should not change the file size', function (done) {
|
it('Not squashing TIFF to a bit depth of 1 should not change the file size', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||||
sharp(fixtures.inputTiff8BitDepth)
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||||
@ -131,7 +132,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Squashing TIFF to a bit depth of 1 should significantly reduce file size', function (done) {
|
it('Squashing TIFF to a bit depth of 1 should significantly reduce file size', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||||
sharp(fixtures.inputTiff8BitDepth)
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||||
@ -219,7 +220,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF lzw compression with horizontal predictor shrinks test file', function (done) {
|
it('TIFF lzw compression with horizontal predictor shrinks test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -271,7 +272,7 @@ describe('TIFF', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('TIFF ccittfax4 compression shrinks b-w test file', function (done) {
|
it('TIFF ccittfax4 compression shrinks b-w test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiff).size;
|
const startSize = fs.statSync(fixtures.inputTiff).size;
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
@ -311,7 +312,7 @@ describe('TIFF', function () {
|
|||||||
assert.strictEqual(resolutionUnit, 'cm');
|
assert.strictEqual(resolutionUnit, 'cm');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF deflate compression with horizontal predictor shrinks test file', function (done) {
|
it('TIFF deflate compression with horizontal predictor shrinks test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -326,7 +327,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF deflate compression with float predictor shrinks test file', function (done) {
|
it('TIFF deflate compression with float predictor shrinks test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -341,7 +342,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF deflate compression without predictor shrinks test file', function (done) {
|
it('TIFF deflate compression without predictor shrinks test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -356,7 +357,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF jpeg compression shrinks test file', function (done) {
|
it('TIFF jpeg compression shrinks test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -430,7 +431,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF tiled pyramid image without compression enlarges test file', function (done) {
|
it('TIFF tiled pyramid image without compression enlarges test file', function (_t, done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -520,7 +521,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF file input with invalid page fails gracefully', function (done) {
|
it('TIFF file input with invalid page fails gracefully', function (_t, done) {
|
||||||
sharp(fixtures.inputTiffMultipage, { page: 2 })
|
sharp(fixtures.inputTiffMultipage, { page: 2 })
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
@ -528,7 +529,7 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF buffer input with invalid page fails gracefully', function (done) {
|
it('TIFF buffer input with invalid page fails gracefully', function (_t, done) {
|
||||||
sharp(fs.readFileSync(fixtures.inputTiffMultipage), { page: 2 })
|
sharp(fs.readFileSync(fixtures.inputTiffMultipage), { page: 2 })
|
||||||
.toBuffer(function (err) {
|
.toBuffer(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const extractZip = require('extract-zip');
|
const extractZip = require('extract-zip');
|
||||||
@ -329,7 +330,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.dz.output.file) {
|
if (sharp.format.dz.output.file) {
|
||||||
it('Deep Zoom layout', function (done) {
|
it('Deep Zoom layout', function (_t, done) {
|
||||||
const directory = fixtures.path('output.dzi_files');
|
const directory = fixtures.path('output.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -345,7 +346,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with custom size+overlap', function (done) {
|
it('Deep Zoom layout with custom size+overlap', function (_t, done) {
|
||||||
const directory = fixtures.path('output.512.dzi_files');
|
const directory = fixtures.path('output.512.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -367,7 +368,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with custom size+angle', function (done) {
|
it('Deep Zoom layout with custom size+angle', function (_t, done) {
|
||||||
const directory = fixtures.path('output.512_90.dzi_files');
|
const directory = fixtures.path('output.512_90.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -401,7 +402,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with depth of one', function (done) {
|
it('Deep Zoom layout with depth of one', function (_t, done) {
|
||||||
const directory = fixtures.path('output.512_depth_one.dzi_files');
|
const directory = fixtures.path('output.512_depth_one.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -417,7 +418,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with depth of onepixel', function (done) {
|
it('Deep Zoom layout with depth of onepixel', function (_t, done) {
|
||||||
const directory = fixtures.path('output.512_depth_onepixel.dzi_files');
|
const directory = fixtures.path('output.512_depth_onepixel.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -433,7 +434,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with depth of onetile', function (done) {
|
it('Deep Zoom layout with depth of onetile', function (_t, done) {
|
||||||
const directory = fixtures.path('output.256_depth_onetile.dzi_files');
|
const directory = fixtures.path('output.256_depth_onetile.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -449,7 +450,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deep Zoom layout with skipBlanks', function (done) {
|
it('Deep Zoom layout with skipBlanks', function (_t, done) {
|
||||||
const directory = fixtures.path('output.256_skip_blanks.dzi_files');
|
const directory = fixtures.path('output.256_skip_blanks.dzi_files');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpgOverlayLayer2)
|
sharp(fixtures.inputJpgOverlayLayer2)
|
||||||
@ -468,7 +469,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Zoomify layout', function (done) {
|
it('Zoomify layout', function (_t, done) {
|
||||||
const directory = fixtures.path('output.zoomify.dzi');
|
const directory = fixtures.path('output.zoomify.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -492,7 +493,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Zoomify layout with depth one', function (done) {
|
it('Zoomify layout with depth one', function (_t, done) {
|
||||||
const directory = fixtures.path('output.zoomify.depth_one.dzi');
|
const directory = fixtures.path('output.zoomify.depth_one.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -513,7 +514,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Zoomify layout with depth onetile', function (done) {
|
it('Zoomify layout with depth onetile', function (_t, done) {
|
||||||
const directory = fixtures.path('output.zoomify.depth_onetile.dzi');
|
const directory = fixtures.path('output.zoomify.depth_onetile.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -534,7 +535,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Zoomify layout with depth onepixel', function (done) {
|
it('Zoomify layout with depth onepixel', function (_t, done) {
|
||||||
const directory = fixtures.path('output.zoomify.depth_onepixel.dzi');
|
const directory = fixtures.path('output.zoomify.depth_onepixel.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -555,7 +556,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Zoomify layout with skip blanks', function (done) {
|
it('Zoomify layout with skip blanks', function (_t, done) {
|
||||||
const directory = fixtures.path('output.zoomify.skipBlanks.dzi');
|
const directory = fixtures.path('output.zoomify.skipBlanks.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpgOverlayLayer2)
|
sharp(fixtures.inputJpgOverlayLayer2)
|
||||||
@ -579,7 +580,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout', function (done) {
|
it('Google layout', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google.dzi');
|
const directory = fixtures.path('output.google.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -603,7 +604,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with jpeg format', function (done) {
|
it('Google layout with jpeg format', function (_t, done) {
|
||||||
const directory = fixtures.path('output.jpg.google.dzi');
|
const directory = fixtures.path('output.jpg.google.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -640,7 +641,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with png format', function (done) {
|
it('Google layout with png format', function (_t, done) {
|
||||||
const directory = fixtures.path('output.png.google.dzi');
|
const directory = fixtures.path('output.png.google.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -677,7 +678,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with webp format', function (done) {
|
it('Google layout with webp format', function (_t, done) {
|
||||||
const directory = fixtures.path('output.webp.google.dzi');
|
const directory = fixtures.path('output.webp.google.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -715,7 +716,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with depth one', function (done) {
|
it('Google layout with depth one', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google_depth_one.dzi');
|
const directory = fixtures.path('output.google_depth_one.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -736,7 +737,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with depth onetile', function (done) {
|
it('Google layout with depth onetile', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google_depth_onetile.dzi');
|
const directory = fixtures.path('output.google_depth_onetile.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -757,7 +758,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with default skip Blanks', function (done) {
|
it('Google layout with default skip Blanks', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google_depth_skipBlanks.dzi');
|
const directory = fixtures.path('output.google_depth_skipBlanks.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
@ -781,7 +782,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with center image in tile', function (done) {
|
it('Google layout with center image in tile', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google_center.dzi');
|
const directory = fixtures.path('output.google_center.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -801,7 +802,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Google layout with center image in tile centre', function (done) {
|
it('Google layout with center image in tile centre', function (_t, done) {
|
||||||
const directory = fixtures.path('output.google_center.dzi');
|
const directory = fixtures.path('output.google_center.dzi');
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@ -821,7 +822,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('IIIFv2 layout', function (done) {
|
it('IIIFv2 layout', function (_t, done) {
|
||||||
const name = 'output.iiif.info';
|
const name = 'output.iiif.info';
|
||||||
const directory = fixtures.path(name);
|
const directory = fixtures.path(name);
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
@ -851,7 +852,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('IIIFv3 layout', function (done) {
|
it('IIIFv3 layout', function (_t, done) {
|
||||||
const name = 'output.iiif3.info';
|
const name = 'output.iiif3.info';
|
||||||
const directory = fixtures.path(name);
|
const directory = fixtures.path(name);
|
||||||
fs.rm(directory, { recursive: true }, function () {
|
fs.rm(directory, { recursive: true }, function () {
|
||||||
@ -882,7 +883,7 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Write to ZIP container using file extension', function (done) {
|
it('Write to ZIP container using file extension', function (_t, done) {
|
||||||
const container = fixtures.path('output.dz.container.zip');
|
const container = fixtures.path('output.dz.container.zip');
|
||||||
const extractTo = fixtures.path('output.dz.container');
|
const extractTo = fixtures.path('output.dz.container');
|
||||||
const directory = path.join(extractTo, 'output.dz.container_files');
|
const directory = path.join(extractTo, 'output.dz.container_files');
|
||||||
@ -903,13 +904,13 @@ describe('Tile', function () {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
assertDeepZoomTiles(directory, 256, 13, done);
|
assertDeepZoomTiles(directory, 256, 13, done);
|
||||||
})
|
})
|
||||||
.catch(done);
|
.catch(_t, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Write to ZIP container using container tile option', function (done) {
|
it('Write to ZIP container using container tile option', function (_t, done) {
|
||||||
const container = fixtures.path('output.dz.containeropt.zip');
|
const container = fixtures.path('output.dz.containeropt.zip');
|
||||||
const extractTo = fixtures.path('output.dz.containeropt');
|
const extractTo = fixtures.path('output.dz.containeropt');
|
||||||
const directory = path.join(extractTo, 'output.dz.containeropt_files');
|
const directory = path.join(extractTo, 'output.dz.containeropt_files');
|
||||||
@ -934,13 +935,13 @@ describe('Tile', function () {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
assertDeepZoomTiles(directory, 256, 13, done);
|
assertDeepZoomTiles(directory, 256, 13, done);
|
||||||
})
|
})
|
||||||
.catch(done);
|
.catch(_t, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Write ZIP container to Buffer', function (done) {
|
it('Write ZIP container to Buffer', function (_t, done) {
|
||||||
const container = fixtures.path('output.dz.tiles.zip');
|
const container = fixtures.path('output.dz.tiles.zip');
|
||||||
const extractTo = fixtures.path('output.dz.tiles');
|
const extractTo = fixtures.path('output.dz.tiles');
|
||||||
const directory = path.join(extractTo, 'output.dz.tiles_files');
|
const directory = path.join(extractTo, 'output.dz.tiles_files');
|
||||||
@ -963,7 +964,7 @@ describe('Tile', function () {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
assertDeepZoomTiles(directory, 256, 13, done);
|
assertDeepZoomTiles(directory, 256, 13, done);
|
||||||
})
|
})
|
||||||
.catch(done);
|
.catch(_t, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -10,7 +11,7 @@ const fixtures = require('../fixtures');
|
|||||||
const maxDistance = 6;
|
const maxDistance = 6;
|
||||||
|
|
||||||
describe('Tint', function () {
|
describe('Tint', function () {
|
||||||
it('tints rgb image red', function (done) {
|
it('tints rgb image red', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-red.jpg');
|
const output = fixtures.path('output.tint-red.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -23,7 +24,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints rgb image green', function (done) {
|
it('tints rgb image green', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-green.jpg');
|
const output = fixtures.path('output.tint-green.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -36,7 +37,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints rgb image blue', function (done) {
|
it('tints rgb image blue', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-blue.jpg');
|
const output = fixtures.path('output.tint-blue.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -49,7 +50,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints rgb image with sepia tone', function (done) {
|
it('tints rgb image with sepia tone', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-sepia-hex.jpg');
|
const output = fixtures.path('output.tint-sepia-hex.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -63,7 +64,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints rgb image with sepia tone with rgb colour', function (done) {
|
it('tints rgb image with sepia tone with rgb colour', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-sepia-rgb.jpg');
|
const output = fixtures.path('output.tint-sepia-rgb.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -77,7 +78,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints rgb image with alpha channel', function (done) {
|
it('tints rgb image with alpha channel', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-alpha.png');
|
const output = fixtures.path('output.tint-alpha.png');
|
||||||
sharp(fixtures.inputPngRGBWithAlpha)
|
sharp(fixtures.inputPngRGBWithAlpha)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@ -91,7 +92,7 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tints cmyk image red', function (done) {
|
it('tints cmyk image red', function (_t, done) {
|
||||||
const output = fixtures.path('output.tint-cmyk.jpg');
|
const output = fixtures.path('output.tint-cmyk.jpg');
|
||||||
sharp(fixtures.inputJpgWithCmykProfile)
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@ -8,7 +9,7 @@ const inRange = require('../../lib/is').inRange;
|
|||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Trim borders', function () {
|
describe('Trim borders', function () {
|
||||||
it('Skip shrink-on-load', function (done) {
|
it('Skip shrink-on-load', function (_t, done) {
|
||||||
const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg');
|
const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg');
|
||||||
sharp(fixtures.inputJpgOverlayLayer2)
|
sharp(fixtures.inputJpgOverlayLayer2)
|
||||||
.trim()
|
.trim()
|
||||||
@ -41,7 +42,7 @@ describe('Trim borders', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel', function (done) {
|
it('16-bit PNG with alpha channel', function (_t, done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 32)
|
.resize(32, 32)
|
||||||
.trim({
|
.trim({
|
||||||
@ -60,7 +61,7 @@ describe('Trim borders', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Attempt to trim 2x2 pixel image fails', function (done) {
|
it('Attempt to trim 2x2 pixel image fails', function (_t, done) {
|
||||||
sharp({
|
sharp({
|
||||||
create: {
|
create: {
|
||||||
width: 2,
|
width: 2,
|
||||||
@ -78,7 +79,7 @@ describe('Trim borders', function () {
|
|||||||
assert.strictEqual('Image to trim must be at least 3x3 pixels', err.message);
|
assert.strictEqual('Image to trim must be at least 3x3 pixels', err.message);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(done);
|
.catch(_t, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should rotate before trim', () =>
|
it('Should rotate before trim', () =>
|
||||||
|
|||||||
@ -1,25 +1,26 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('Unflatten', function () {
|
describe('Unflatten', function () {
|
||||||
it('unflatten white background', function (done) {
|
it('unflatten white background', function (_t, done) {
|
||||||
sharp(fixtures.inputPng).unflatten()
|
sharp(fixtures.inputPng).unflatten()
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
fixtures.assertSimilar(fixtures.expected('unflatten-white-transparent.png'), data, { threshold: 0 }, done);
|
fixtures.assertSimilar(fixtures.expected('unflatten-white-transparent.png'), data, { threshold: 0 }, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('unflatten transparent image', function (done) {
|
it('unflatten transparent image', function (_t, done) {
|
||||||
sharp(fixtures.inputPngTrimSpecificColourIncludeAlpha).unflatten()
|
sharp(fixtures.inputPngTrimSpecificColourIncludeAlpha).unflatten()
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
fixtures.assertSimilar(fixtures.expected('unflatten-flag-white-transparent.png'), data, { threshold: 0 }, done);
|
fixtures.assertSimilar(fixtures.expected('unflatten-flag-white-transparent.png'), data, { threshold: 0 }, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('unflatten using threshold', function (done) {
|
it('unflatten using threshold', function (_t, done) {
|
||||||
sharp(fixtures.inputPngPalette).unflatten().threshold(128, { grayscale: false })
|
sharp(fixtures.inputPngPalette).unflatten().threshold(128, { grayscale: false })
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer(function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|
||||||
describe('Utilities', function () {
|
describe('Utilities', function () {
|
||||||
describe('Cache', function () {
|
describe('Cache', function () {
|
||||||
it('Can be disabled', function (done) {
|
it('Can be disabled', function (_t, done) {
|
||||||
const check = setInterval(() => {
|
const check = setInterval(() => {
|
||||||
const cache = sharp.cache(false);
|
const cache = sharp.cache(false);
|
||||||
const empty =
|
const empty =
|
||||||
@ -75,7 +76,7 @@ describe('Utilities', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Counters', function () {
|
describe('Counters', function () {
|
||||||
it('Have zero value at rest', (done) => {
|
it('Have zero value at rest', (_t, done) => {
|
||||||
queueMicrotask(() => {
|
queueMicrotask(() => {
|
||||||
const counters = sharp.counters();
|
const counters = sharp.counters();
|
||||||
assert.strictEqual(0, counters.queue);
|
assert.strictEqual(0, counters.queue);
|
||||||
|
|||||||
@ -2,13 +2,14 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
const { describe, it } = require('node:test');
|
||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('WebP', function () {
|
describe('WebP', function () {
|
||||||
it('WebP output', function (done) {
|
it('WebP output', function (_t, done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toFormat(sharp.format.webp)
|
.toFormat(sharp.format.webp)
|
||||||
@ -34,7 +35,7 @@ describe('WebP', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for webp alpha quality', function (done) {
|
it('should work for webp alpha quality', function (_t, done) {
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.webp({ alphaQuality: 80, effort: 0 })
|
.webp({ alphaQuality: 80, effort: 0 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -45,7 +46,7 @@ describe('WebP', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for webp lossless', function (done) {
|
it('should work for webp lossless', function (_t, done) {
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.webp({ lossless: true, effort: 0 })
|
.webp({ lossless: true, effort: 0 })
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
@ -56,7 +57,7 @@ describe('WebP', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for webp near-lossless', function (done) {
|
it('should work for webp near-lossless', function (_t, done) {
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.webp({ nearLossless: true, quality: 50, effort: 0 })
|
.webp({ nearLossless: true, quality: 50, effort: 0 })
|
||||||
.toBuffer(function (err50, data50, info50) {
|
.toBuffer(function (err50, data50, info50) {
|
||||||
@ -67,7 +68,7 @@ describe('WebP', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use near-lossless when both lossless and nearLossless are specified', function (done) {
|
it('should use near-lossless when both lossless and nearLossless are specified', function (_t, done) {
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.webp({ nearLossless: true, quality: 50, lossless: true, effort: 0 })
|
.webp({ nearLossless: true, quality: 50, lossless: true, effort: 0 })
|
||||||
.toBuffer(function (err50, data50, info50) {
|
.toBuffer(function (err50, data50, info50) {
|
||||||
@ -269,7 +270,7 @@ describe('WebP', function () {
|
|||||||
assert.deepStrictEqual(updated.delay, [120, 120, 90, 120, 120, 90, 120, 90, 30]);
|
assert.deepStrictEqual(updated.delay, [120, 120, 90, 120, 120, 90, 120, 90, 30]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with streams when only animated is set', function (done) {
|
it('should work with streams when only animated is set', function (_t, done) {
|
||||||
fs.createReadStream(fixtures.inputWebPAnimated)
|
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||||
.pipe(sharp({ animated: true }))
|
.pipe(sharp({ animated: true }))
|
||||||
.webp({ lossless: true, effort: 0 })
|
.webp({ lossless: true, effort: 0 })
|
||||||
@ -281,7 +282,7 @@ describe('WebP', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with streams when only pages is set', function (done) {
|
it('should work with streams when only pages is set', function (_t, done) {
|
||||||
fs.createReadStream(fixtures.inputWebPAnimated)
|
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||||
.pipe(sharp({ pages: -1 }))
|
.pipe(sharp({ pages: -1 }))
|
||||||
.webp({ lossless: true, effort: 0 })
|
.webp({ lossless: true, effort: 0 })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user