Default PNG output to adaptiveFiltering=false, compressionLevel=9

PNG is mostly used for logos and line art, so these defaults will
produce the smallest files for most output most of the time.
This commit is contained in:
Lovell Fuller 2017-10-01 18:16:31 +01:00
parent 7b6c80327e
commit 99076edc89
5 changed files with 33 additions and 6 deletions

View File

@ -10,6 +10,10 @@ Requires libvips v8.6.0.
[#868](https://github.com/lovell/sharp/issues/868)
[@mirohristov-com](https://github.com/mirohristov-com)
* PNG output now defaults to adaptiveFiltering=false, compressionLevel=9
[#872](https://github.com/lovell/sharp/issues/872)
[@wmertens](https://github.com/wmertens)
### v0.18 - "*ridge*"
Requires libvips v8.5.5.

View File

@ -186,8 +186,8 @@ const Sharp = function (input, options) {
jpegOvershootDeringing: false,
jpegOptimiseScans: false,
pngProgressive: false,
pngCompressionLevel: 6,
pngAdaptiveFiltering: true,
pngCompressionLevel: 9,
pngAdaptiveFiltering: false,
webpQuality: 80,
webpAlphaQuality: 100,
webpLossless: false,

View File

@ -148,8 +148,8 @@ function jpeg (options) {
* Use these PNG options for output image.
* @param {Object} [options]
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
* @param {Number} [options.compressionLevel=6] - zlib compression level
* @param {Boolean} [options.adaptiveFiltering=true] - use adaptive row filtering
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
* @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
* @param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
* @returns {Sharp}
* @throws {Error} Invalid options

View File

@ -179,8 +179,8 @@ struct PipelineBaton {
jpegOvershootDeringing(false),
jpegOptimiseScans(false),
pngProgressive(false),
pngCompressionLevel(6),
pngAdaptiveFiltering(true),
pngCompressionLevel(9),
pngAdaptiveFiltering(false),
webpQuality(80),
tiffQuality(80),
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),

View File

@ -628,6 +628,29 @@ describe('Input/output', function () {
});
});
it('default compressionLevel generates smaller file than compressionLevel=6', function (done) {
// First generate with default compressionLevel
sharp(fixtures.inputPng)
.resize(320, 240)
.png()
.toBuffer(function (err, defaultData, defaultInfo) {
if (err) throw err;
assert.strictEqual(true, defaultData.length > 0);
assert.strictEqual('png', defaultInfo.format);
// Then generate with compressionLevel=6
sharp(fixtures.inputPng)
.resize(320, 240)
.png({ compressionLevel: 6 })
.toBuffer(function (err, largerData, largerInfo) {
if (err) throw err;
assert.strictEqual(true, largerData.length > 0);
assert.strictEqual('png', largerInfo.format);
assert.strictEqual(true, defaultData.length < largerData.length);
done();
});
});
});
it('without adaptiveFiltering generates smaller file', function (done) {
// First generate with adaptive filtering
sharp(fixtures.inputPng)