mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Remove use of deprecated functions from test code
This commit is contained in:
parent
55998707a5
commit
deb978bf57
@ -14,6 +14,7 @@ let versions = {
|
|||||||
(function () {
|
(function () {
|
||||||
// Does libvips meet minimum requirement?
|
// Does libvips meet minimum requirement?
|
||||||
const libvipsVersionMin = require('../package.json').config.libvips;
|
const libvipsVersionMin = require('../package.json').config.libvips;
|
||||||
|
/* istanbul ignore if */
|
||||||
if (semver.lt(versions.vips, libvipsVersionMin)) {
|
if (semver.lt(versions.vips, libvipsVersionMin)) {
|
||||||
throw new Error('Found libvips ' + versions.vips + ' but require at least ' + libvipsVersionMin);
|
throw new Error('Found libvips ' + versions.vips + ' but require at least ' + libvipsVersionMin);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,9 @@ const _createInputDescriptor = function _createInputDescriptor (input, inputOpti
|
|||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
const _write = function _write (chunk, encoding, callback) {
|
const _write = 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)) {
|
||||||
this.options.input.buffer.push(chunk);
|
this.options.input.buffer.push(chunk);
|
||||||
callback();
|
callback();
|
||||||
|
@ -91,6 +91,7 @@ const withMetadata = function withMetadata (withMetadata) {
|
|||||||
* @param {Boolean} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg
|
* @param {Boolean} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg
|
||||||
* @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
|
* @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
|
||||||
* @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
|
* @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
|
||||||
|
* @param {Boolean} [optimizeScans=false] - alternative spelling of optimiseScans
|
||||||
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@ -121,7 +122,7 @@ const jpeg = function jpeg (options) {
|
|||||||
if (is.defined(options.overshootDeringing)) {
|
if (is.defined(options.overshootDeringing)) {
|
||||||
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
|
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
|
||||||
}
|
}
|
||||||
options.optimiseScans = options.optimiseScans || options.optimizeScans;
|
options.optimiseScans = is.bool(options.optimiseScans) ? options.optimiseScans : options.optimizeScans;
|
||||||
if (is.defined(options.optimiseScans)) {
|
if (is.defined(options.optimiseScans)) {
|
||||||
this._setBooleanOption('jpegOptimiseScans', options.optimiseScans);
|
this._setBooleanOption('jpegOptimiseScans', options.optimiseScans);
|
||||||
if (options.optimiseScans) {
|
if (options.optimiseScans) {
|
||||||
@ -170,13 +171,11 @@ const png = function png (options) {
|
|||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
const webp = function webp (options) {
|
const webp = function webp (options) {
|
||||||
if (is.object(options)) {
|
if (is.object(options) && is.defined(options.quality)) {
|
||||||
if (is.defined(options.quality)) {
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
this.options.webpQuality = options.quality;
|
||||||
this.options.webpQuality = options.quality;
|
} else {
|
||||||
} else {
|
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
||||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._updateFormatOut('webp', options);
|
return this._updateFormatOut('webp', options);
|
||||||
@ -191,13 +190,11 @@ const webp = function webp (options) {
|
|||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
const tiff = function tiff (options) {
|
const tiff = function tiff (options) {
|
||||||
if (is.object(options)) {
|
if (is.object(options) && is.defined(options.quality)) {
|
||||||
if (is.defined(options.quality)) {
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
this.options.tiffQuality = options.quality;
|
||||||
this.options.tiffQuality = options.quality;
|
} else {
|
||||||
} else {
|
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
||||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._updateFormatOut('tiff', options);
|
return this._updateFormatOut('tiff', options);
|
||||||
@ -412,6 +409,7 @@ const _pipeline = function _pipeline (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Deprecated output options
|
// Deprecated output options
|
||||||
|
/* istanbul ignore next */
|
||||||
const quality = util.deprecate(function (quality) {
|
const quality = util.deprecate(function (quality) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
const options = { quality: quality };
|
const options = { quality: quality };
|
||||||
@ -419,6 +417,7 @@ const quality = util.deprecate(function (quality) {
|
|||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'quality: use jpeg({ quality: ... }), webp({ quality: ... }) and/or tiff({ quality: ... }) instead');
|
}, 'quality: use jpeg({ quality: ... }), webp({ quality: ... }) and/or tiff({ quality: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const progressive = util.deprecate(function (progressive) {
|
const progressive = util.deprecate(function (progressive) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
const options = { progressive: (progressive !== false) };
|
const options = { progressive: (progressive !== false) };
|
||||||
@ -426,36 +425,42 @@ const progressive = util.deprecate(function (progressive) {
|
|||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'progressive: use jpeg({ progressive: ... }) and/or png({ progressive: ... }) instead');
|
}, 'progressive: use jpeg({ progressive: ... }) and/or png({ progressive: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const compressionLevel = util.deprecate(function (compressionLevel) {
|
const compressionLevel = util.deprecate(function (compressionLevel) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.png({ compressionLevel: compressionLevel });
|
this.png({ compressionLevel: compressionLevel });
|
||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'compressionLevel: use png({ compressionLevel: ... }) instead');
|
}, 'compressionLevel: use png({ compressionLevel: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const withoutAdaptiveFiltering = util.deprecate(function (withoutAdaptiveFiltering) {
|
const withoutAdaptiveFiltering = util.deprecate(function (withoutAdaptiveFiltering) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.png({ adaptiveFiltering: (withoutAdaptiveFiltering === false) });
|
this.png({ adaptiveFiltering: (withoutAdaptiveFiltering === false) });
|
||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'withoutAdaptiveFiltering: use png({ adaptiveFiltering: ... }) instead');
|
}, 'withoutAdaptiveFiltering: use png({ adaptiveFiltering: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const withoutChromaSubsampling = util.deprecate(function (withoutChromaSubsampling) {
|
const withoutChromaSubsampling = util.deprecate(function (withoutChromaSubsampling) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.jpeg({ chromaSubsampling: (withoutChromaSubsampling === false) ? '4:2:0' : '4:4:4' });
|
this.jpeg({ chromaSubsampling: (withoutChromaSubsampling === false) ? '4:2:0' : '4:4:4' });
|
||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'withoutChromaSubsampling: use jpeg({ chromaSubsampling: "4:4:4" }) instead');
|
}, 'withoutChromaSubsampling: use jpeg({ chromaSubsampling: "4:4:4" }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const trellisQuantisation = util.deprecate(function (trellisQuantisation) {
|
const trellisQuantisation = util.deprecate(function (trellisQuantisation) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.jpeg({ trellisQuantisation: (trellisQuantisation !== false) });
|
this.jpeg({ trellisQuantisation: (trellisQuantisation !== false) });
|
||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'trellisQuantisation: use jpeg({ trellisQuantisation: ... }) instead');
|
}, 'trellisQuantisation: use jpeg({ trellisQuantisation: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const overshootDeringing = util.deprecate(function (overshootDeringing) {
|
const overshootDeringing = util.deprecate(function (overshootDeringing) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.jpeg({ overshootDeringing: (overshootDeringing !== false) });
|
this.jpeg({ overshootDeringing: (overshootDeringing !== false) });
|
||||||
this.options.formatOut = formatOut;
|
this.options.formatOut = formatOut;
|
||||||
return this;
|
return this;
|
||||||
}, 'overshootDeringing: use jpeg({ overshootDeringing: ... }) instead');
|
}, 'overshootDeringing: use jpeg({ overshootDeringing: ... }) instead');
|
||||||
|
/* istanbul ignore next */
|
||||||
const optimiseScans = util.deprecate(function (optimiseScans) {
|
const optimiseScans = util.deprecate(function (optimiseScans) {
|
||||||
const formatOut = this.options.formatOut;
|
const formatOut = this.options.formatOut;
|
||||||
this.jpeg({ optimiseScans: (optimiseScans !== false) });
|
this.jpeg({ optimiseScans: (optimiseScans !== false) });
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=96 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"test-packaging": "./packaging/test-linux-x64.sh",
|
"test-packaging": "./packaging/test-linux-x64.sh",
|
||||||
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
||||||
|
@ -140,7 +140,7 @@ make install
|
|||||||
mkdir ${DEPS}/fontconfig
|
mkdir ${DEPS}/fontconfig
|
||||||
curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
|
curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
|
||||||
cd ${DEPS}/fontconfig
|
cd ${DEPS}/fontconfig
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2
|
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2 --sysconfdir=/etc
|
||||||
make install-strip
|
make install-strip
|
||||||
|
|
||||||
mkdir ${DEPS}/harfbuzz
|
mkdir ${DEPS}/harfbuzz
|
||||||
|
@ -17,7 +17,7 @@ describe('Colour space conversion', function () {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.gamma()
|
.gamma()
|
||||||
.greyscale()
|
.grayscale()
|
||||||
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
448
test/unit/io.js
448
test/unit/io.js
@ -266,51 +266,41 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Promises/A+', function (done) {
|
it('Promises/A+', function () {
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function (data) {
|
return sharp(fixtures.inputJpg)
|
||||||
sharp(data).toBuffer(function (err, data, info) {
|
.resize(320, 240)
|
||||||
if (err) throw err;
|
.toBuffer();
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual(data.length, info.size);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(320, info.width);
|
|
||||||
assert.strictEqual(240, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}).catch(function (err) {
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('JPEG quality', function (done) {
|
it('JPEG quality', function (done) {
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).quality(70).toBuffer(function (err, buffer70) {
|
sharp(fixtures.inputJpg)
|
||||||
if (err) throw err;
|
.resize(320, 240)
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, buffer80) {
|
.jpeg({ quality: 70 })
|
||||||
|
.toBuffer(function (err, buffer70) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).quality(90).toBuffer(function (err, buffer90) {
|
sharp(fixtures.inputJpg)
|
||||||
if (err) throw err;
|
.resize(320, 240)
|
||||||
assert(buffer70.length < buffer80.length);
|
.toBuffer(function (err, buffer80) {
|
||||||
assert(buffer80.length < buffer90.length);
|
if (err) throw err;
|
||||||
done();
|
sharp(fixtures.inputJpg)
|
||||||
});
|
.resize(320, 240)
|
||||||
|
.jpeg({ quality: 90 })
|
||||||
|
.toBuffer(function (err, buffer90) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert(buffer70.length < buffer80.length);
|
||||||
|
assert(buffer80.length < buffer90.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Invalid quality', function () {
|
describe('Invalid JPEG quality', function () {
|
||||||
it('Negative integer', function () {
|
[-1, 88.2, 'test'].forEach(function (quality) {
|
||||||
assert.throws(function () {
|
it(quality.toString(), function () {
|
||||||
sharp(fixtures.inputJpg).quality(-1);
|
assert.throws(function () {
|
||||||
});
|
sharp().jpeg({ quality: quality });
|
||||||
});
|
});
|
||||||
it('Non integral', function () {
|
|
||||||
assert.throws(function () {
|
|
||||||
sharp(fixtures.inputJpg).quality(88.2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('String', function () {
|
|
||||||
assert.throws(function () {
|
|
||||||
sharp(fixtures.inputJpg).quality('test');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -318,7 +308,7 @@ describe('Input/output', function () {
|
|||||||
it('Progressive JPEG image', function (done) {
|
it('Progressive JPEG image', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.progressive(false)
|
.jpeg({ progressive: false })
|
||||||
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, nonProgressiveData.length > 0);
|
assert.strictEqual(true, nonProgressiveData.length > 0);
|
||||||
@ -328,7 +318,7 @@ describe('Input/output', function () {
|
|||||||
assert.strictEqual(240, nonProgressiveInfo.height);
|
assert.strictEqual(240, nonProgressiveInfo.height);
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.progressive()
|
.jpeg({ progressive: true })
|
||||||
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, progressiveData.length > 0);
|
assert.strictEqual(true, progressiveData.length > 0);
|
||||||
@ -345,8 +335,7 @@ describe('Input/output', function () {
|
|||||||
it('Progressive PNG image', function (done) {
|
it('Progressive PNG image', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.png()
|
.png({ progressive: false })
|
||||||
.progressive(false)
|
|
||||||
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, nonProgressiveData.length > 0);
|
assert.strictEqual(true, nonProgressiveData.length > 0);
|
||||||
@ -355,7 +344,7 @@ describe('Input/output', function () {
|
|||||||
assert.strictEqual(320, nonProgressiveInfo.width);
|
assert.strictEqual(320, nonProgressiveInfo.width);
|
||||||
assert.strictEqual(240, nonProgressiveInfo.height);
|
assert.strictEqual(240, nonProgressiveInfo.height);
|
||||||
sharp(nonProgressiveData)
|
sharp(nonProgressiveData)
|
||||||
.progressive()
|
.png({ progressive: true })
|
||||||
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
.toBuffer(function (err, progressiveData, progressiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, progressiveData.length > 0);
|
assert.strictEqual(true, progressiveData.length > 0);
|
||||||
@ -440,37 +429,33 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.webp.input.file) {
|
it('Match WebP input', function (done) {
|
||||||
it('Match WebP input', function (done) {
|
sharp(fixtures.inputWebP)
|
||||||
sharp(fixtures.inputWebP)
|
.resize(320, 80)
|
||||||
.resize(320, 80)
|
.toFile(fixtures.outputZoinks, function (err, info) {
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
if (err) throw err;
|
||||||
if (err) throw err;
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(80, info.height);
|
||||||
assert.strictEqual(80, info.height);
|
fs.unlinkSync(fixtures.outputZoinks);
|
||||||
fs.unlinkSync(fixtures.outputZoinks);
|
done();
|
||||||
done();
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sharp.format.tiff.input.file) {
|
it('Match TIFF input', function (done) {
|
||||||
it('Match TIFF input', function (done) {
|
sharp(fixtures.inputTiff)
|
||||||
sharp(fixtures.inputTiff)
|
.resize(320, 80)
|
||||||
.resize(320, 80)
|
.toFile(fixtures.outputZoinks, function (err, info) {
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
if (err) throw err;
|
||||||
if (err) throw err;
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(80, info.height);
|
||||||
assert.strictEqual(80, info.height);
|
fs.unlinkSync(fixtures.outputZoinks);
|
||||||
fs.unlinkSync(fixtures.outputZoinks);
|
done();
|
||||||
done();
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
it('Match GIF input, therefore fail', function (done) {
|
it('Match GIF input, therefore fail', function (done) {
|
||||||
sharp(fixtures.inputGif)
|
sharp(fixtures.inputGif)
|
||||||
@ -498,31 +483,23 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('PNG output', function () {
|
describe('PNG output', function () {
|
||||||
it('compression level is valid', function (done) {
|
it('compression level is valid', function () {
|
||||||
let isValid = false;
|
assert.doesNotThrow(function () {
|
||||||
try {
|
sharp().png({ compressionLevel: 0 });
|
||||||
sharp().compressionLevel(0);
|
});
|
||||||
isValid = true;
|
|
||||||
} catch (e) {}
|
|
||||||
assert(isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('compression level is invalid', function (done) {
|
it('compression level is invalid', function () {
|
||||||
let isValid = false;
|
assert.throws(function () {
|
||||||
try {
|
sharp().png({ compressionLevel: -1 });
|
||||||
sharp().compressionLevel(-1);
|
});
|
||||||
isValid = true;
|
|
||||||
} catch (e) {}
|
|
||||||
assert(!isValid);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('withoutAdaptiveFiltering generates smaller file', function (done) {
|
it('without adaptiveFiltering generates smaller file', function (done) {
|
||||||
// First generate with adaptive filtering
|
// First generate with adaptive filtering
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withoutAdaptiveFiltering(false)
|
.png({ adaptiveFiltering: true })
|
||||||
.toBuffer(function (err, adaptiveData, adaptiveInfo) {
|
.toBuffer(function (err, adaptiveData, adaptiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, adaptiveData.length > 0);
|
assert.strictEqual(true, adaptiveData.length > 0);
|
||||||
@ -533,7 +510,7 @@ describe('Input/output', function () {
|
|||||||
// Then generate without
|
// Then generate without
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withoutAdaptiveFiltering()
|
.png({ adaptiveFiltering: false })
|
||||||
.toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) {
|
.toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withoutAdaptiveData.length > 0);
|
assert.strictEqual(true, withoutAdaptiveData.length > 0);
|
||||||
@ -546,13 +523,19 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Invalid PNG adaptiveFiltering value throws error', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp().png({ adaptiveFiltering: 1 });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Without chroma subsampling generates larger file', function (done) {
|
it('Without chroma subsampling generates larger file', function (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)
|
||||||
.withoutChromaSubsampling(false)
|
.jpeg({ chromaSubsampling: '4:2:0' })
|
||||||
.toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) {
|
.toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withChromaSubsamplingData.length > 0);
|
assert.strictEqual(true, withChromaSubsamplingData.length > 0);
|
||||||
@ -563,7 +546,7 @@ describe('Input/output', function () {
|
|||||||
// Then generate without
|
// Then generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.withoutChromaSubsampling()
|
.jpeg({ chromaSubsampling: '4:4:4' })
|
||||||
.toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) {
|
.toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withoutChromaSubsamplingData.length > 0);
|
assert.strictEqual(true, withoutChromaSubsamplingData.length > 0);
|
||||||
@ -577,11 +560,17 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Invalid JPEG chromaSubsampling value throws error', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp().jpeg({ chromaSubsampling: '4:2:2' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Trellis quantisation', function (done) {
|
it('Trellis quantisation', function (done) {
|
||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.trellisQuantisation(false)
|
.jpeg({ trellisQuantisation: false })
|
||||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withoutData.length > 0);
|
assert.strictEqual(true, withoutData.length > 0);
|
||||||
@ -592,7 +581,7 @@ describe('Input/output', function () {
|
|||||||
// Then generate with
|
// Then generate with
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.trellisQuantization()
|
.jpeg({ trellisQuantization: true })
|
||||||
.toBuffer(function (err, withData, withInfo) {
|
.toBuffer(function (err, withData, withInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withData.length > 0);
|
assert.strictEqual(true, withData.length > 0);
|
||||||
@ -611,7 +600,7 @@ describe('Input/output', function () {
|
|||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.overshootDeringing(false)
|
.jpeg({ overshootDeringing: false })
|
||||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withoutData.length > 0);
|
assert.strictEqual(true, withoutData.length > 0);
|
||||||
@ -622,7 +611,7 @@ describe('Input/output', function () {
|
|||||||
// Then generate with
|
// Then generate with
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.overshootDeringing()
|
.jpeg({ overshootDeringing: true })
|
||||||
.toBuffer(function (err, withData, withInfo) {
|
.toBuffer(function (err, withData, withInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withData.length > 0);
|
assert.strictEqual(true, withData.length > 0);
|
||||||
@ -635,11 +624,11 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Optimise scans', function (done) {
|
it('Optimise scans generates different output length', function (done) {
|
||||||
// First generate without
|
// First generate without
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.optimiseScans(false)
|
.jpeg({ optimiseScans: false })
|
||||||
.toBuffer(function (err, withoutData, withoutInfo) {
|
.toBuffer(function (err, withoutData, withoutInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withoutData.length > 0);
|
assert.strictEqual(true, withoutData.length > 0);
|
||||||
@ -650,7 +639,7 @@ describe('Input/output', function () {
|
|||||||
// Then generate with
|
// Then generate with
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.optimizeScans()
|
.jpeg({ optimizeScans: true })
|
||||||
.toBuffer(function (err, withData, withInfo) {
|
.toBuffer(function (err, withData, withInfo) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, withData.length > 0);
|
assert.strictEqual(true, withData.length > 0);
|
||||||
@ -720,138 +709,157 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sharp.format.tiff.input.buffer) {
|
it('Load TIFF from Buffer', function (done) {
|
||||||
it('Load TIFF from Buffer', function (done) {
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
sharp(inputTiffBuffer)
|
||||||
sharp(inputTiffBuffer)
|
.resize(320, 240)
|
||||||
.resize(320, 240)
|
.jpeg()
|
||||||
.jpeg()
|
.toBuffer(function (err, data, info) {
|
||||||
.toBuffer(function (err, data, info) {
|
if (err) throw err;
|
||||||
if (err) throw err;
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(240, info.height);
|
||||||
assert.strictEqual(240, info.height);
|
done();
|
||||||
done();
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sharp.format.gif.input.buffer) {
|
it('Invalid WebP quality throws error', function () {
|
||||||
it('Load GIF from Buffer', function (done) {
|
assert.throws(function () {
|
||||||
const inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
sharp().webp({ quality: 101 });
|
||||||
sharp(inputGifBuffer)
|
|
||||||
.resize(320, 240)
|
|
||||||
.jpeg()
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual(data.length, info.size);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(320, info.width);
|
|
||||||
assert.strictEqual(240, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
if (sharp.format.gif.input.file) {
|
it('Invalid TIFF quality throws error', function () {
|
||||||
it('Load GIF grey+alpha from file', function (done) {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputGifGreyPlusAlpha)
|
sharp().tiff({ quality: 101 });
|
||||||
.resize(8, 4)
|
|
||||||
.png()
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual(data.length, info.size);
|
|
||||||
assert.strictEqual('png', info.format);
|
|
||||||
assert.strictEqual(8, info.width);
|
|
||||||
assert.strictEqual(4, info.height);
|
|
||||||
assert.strictEqual(4, info.channels);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
if (sharp.format.v.input.file) {
|
it('Missing TIFF quality does not throw error', function () {
|
||||||
it('Load Vips V file', function (done) {
|
assert.doesNotThrow(function () {
|
||||||
sharp(fixtures.inputV)
|
sharp().tiff();
|
||||||
.jpeg()
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(true, data.length > 0);
|
|
||||||
assert.strictEqual('jpeg', info.format);
|
|
||||||
assert.strictEqual(70, info.width);
|
|
||||||
assert.strictEqual(60, info.height);
|
|
||||||
fixtures.assertSimilar(fixtures.expected('vfile.jpg'), data, done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
if (sharp.format.v.output.file) {
|
it('Input and output formats match when not forcing', function (done) {
|
||||||
it('Save Vips V file', function (done) {
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.png({ compressionLevel: 1, force: false })
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Load GIF from Buffer', function (done) {
|
||||||
|
const inputGifBuffer = fs.readFileSync(fixtures.inputGif);
|
||||||
|
sharp(inputGifBuffer)
|
||||||
|
.resize(320, 240)
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual(data.length, info.size);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Load GIF grey+alpha from file', function (done) {
|
||||||
|
sharp(fixtures.inputGifGreyPlusAlpha)
|
||||||
|
.resize(8, 4)
|
||||||
|
.png()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual(data.length, info.size);
|
||||||
|
assert.strictEqual('png', info.format);
|
||||||
|
assert.strictEqual(8, info.width);
|
||||||
|
assert.strictEqual(4, info.height);
|
||||||
|
assert.strictEqual(4, info.channels);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Load Vips V file', function (done) {
|
||||||
|
sharp(fixtures.inputV)
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(70, info.width);
|
||||||
|
assert.strictEqual(60, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('vfile.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Save Vips V file', function (done) {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.extract({left: 910, top: 1105, width: 70, height: 60})
|
||||||
|
.toFile(fixtures.outputV, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
assert.strictEqual('v', info.format);
|
||||||
|
assert.strictEqual(70, info.width);
|
||||||
|
assert.strictEqual(60, info.height);
|
||||||
|
fs.unlinkSync(fixtures.outputV);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Ouput raw, uncompressed image data', function () {
|
||||||
|
it('1 channel greyscale image', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({left: 910, top: 1105, width: 70, height: 60})
|
.greyscale()
|
||||||
.toFile(fixtures.outputV, function (err, info) {
|
.resize(32, 24)
|
||||||
|
.raw()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(32 * 24 * 1, info.size);
|
||||||
assert.strictEqual('v', info.format);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual(70, info.width);
|
assert.strictEqual('raw', info.format);
|
||||||
assert.strictEqual(60, info.height);
|
assert.strictEqual(32, info.width);
|
||||||
fs.unlinkSync(fixtures.outputV);
|
assert.strictEqual(24, info.height);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
it('3 channel colour image without transparency', function (done) {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
if (sharp.format.raw.output.buffer) {
|
.resize(32, 24)
|
||||||
describe('Ouput raw, uncompressed image data', function () {
|
.toFormat('raw')
|
||||||
it('1 channel greyscale image', function (done) {
|
.toBuffer(function (err, data, info) {
|
||||||
sharp(fixtures.inputJpg)
|
if (err) throw err;
|
||||||
.greyscale()
|
assert.strictEqual(32 * 24 * 3, info.size);
|
||||||
.resize(32, 24)
|
assert.strictEqual(data.length, info.size);
|
||||||
.raw()
|
assert.strictEqual('raw', info.format);
|
||||||
.toBuffer(function (err, data, info) {
|
assert.strictEqual(32, info.width);
|
||||||
if (err) throw err;
|
assert.strictEqual(24, info.height);
|
||||||
assert.strictEqual(32 * 24 * 1, info.size);
|
done();
|
||||||
assert.strictEqual(data.length, info.size);
|
});
|
||||||
assert.strictEqual('raw', info.format);
|
|
||||||
assert.strictEqual(32, info.width);
|
|
||||||
assert.strictEqual(24, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('3 channel colour image without transparency', function (done) {
|
|
||||||
sharp(fixtures.inputJpg)
|
|
||||||
.resize(32, 24)
|
|
||||||
.toFormat('raw')
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(32 * 24 * 3, info.size);
|
|
||||||
assert.strictEqual(data.length, info.size);
|
|
||||||
assert.strictEqual('raw', info.format);
|
|
||||||
assert.strictEqual(32, info.width);
|
|
||||||
assert.strictEqual(24, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('4 channel colour image with transparency', function (done) {
|
|
||||||
sharp(fixtures.inputPngWithTransparency)
|
|
||||||
.resize(32, 24)
|
|
||||||
.toFormat(sharp.format.raw)
|
|
||||||
.toBuffer(function (err, data, info) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.strictEqual(32 * 24 * 4, info.size);
|
|
||||||
assert.strictEqual(data.length, info.size);
|
|
||||||
assert.strictEqual('raw', info.format);
|
|
||||||
assert.strictEqual(32, info.width);
|
|
||||||
assert.strictEqual(24, info.height);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
it('4 channel colour image with transparency', function (done) {
|
||||||
|
sharp(fixtures.inputPngWithTransparency)
|
||||||
|
.resize(32, 24)
|
||||||
|
.toFormat(sharp.format.raw)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(32 * 24 * 4, info.size);
|
||||||
|
assert.strictEqual(data.length, info.size);
|
||||||
|
assert.strictEqual('raw', info.format);
|
||||||
|
assert.strictEqual(32, info.width);
|
||||||
|
assert.strictEqual(24, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Limit pixel count of input image', function () {
|
describe('Limit pixel count of input image', function () {
|
||||||
it('Invalid fails - negative', function (done) {
|
it('Invalid fails - negative', function (done) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user