mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
PNG compression level range is 0-9 #95
This commit is contained in:
parent
fb0769a327
commit
7f8f38f666
@ -378,7 +378,7 @@ Include all metadata (ICC, EXIF, XMP) from the input image in the output image.
|
|||||||
|
|
||||||
An advanced setting for the _zlib_ compression level of the lossless PNG output format. The default level is `6`.
|
An advanced setting for the _zlib_ compression level of the lossless PNG output format. The default level is `6`.
|
||||||
|
|
||||||
`compressionLevel` is a Number between -1 and 9.
|
`compressionLevel` is a Number between 0 and 9.
|
||||||
|
|
||||||
### Output methods
|
### Output methods
|
||||||
|
|
||||||
|
5
index.js
5
index.js
@ -63,6 +63,7 @@ util.inherits(Sharp, stream.Duplex);
|
|||||||
Handle incoming chunk on Writable Stream
|
Handle incoming chunk on Writable Stream
|
||||||
*/
|
*/
|
||||||
Sharp.prototype._write = function(chunk, encoding, callback) {
|
Sharp.prototype._write = function(chunk, encoding, callback) {
|
||||||
|
/*jslint unused: false */
|
||||||
if (this.options.streamIn) {
|
if (this.options.streamIn) {
|
||||||
if (typeof chunk === 'object' || chunk instanceof Buffer) {
|
if (typeof chunk === 'object' || chunk instanceof Buffer) {
|
||||||
if (typeof this.options.bufferIn === 'undefined') {
|
if (typeof this.options.bufferIn === 'undefined') {
|
||||||
@ -229,10 +230,10 @@ Sharp.prototype.quality = function(quality) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Sharp.prototype.compressionLevel = function(compressionLevel) {
|
Sharp.prototype.compressionLevel = function(compressionLevel) {
|
||||||
if (!Number.isNaN(compressionLevel) && compressionLevel >= -1 && compressionLevel <= 9) {
|
if (!Number.isNaN(compressionLevel) && compressionLevel >= 0 && compressionLevel <= 9) {
|
||||||
this.options.compressionLevel = compressionLevel;
|
this.options.compressionLevel = compressionLevel;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid compressionLevel (-1 to 9) ' + compressionLevel);
|
throw new Error('Invalid compressionLevel (0 to 9) ' + compressionLevel);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -815,6 +815,26 @@ async.series([
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// PNG compression level - valid
|
||||||
|
function(done) {
|
||||||
|
var isValid = false;
|
||||||
|
try {
|
||||||
|
sharp().compressionLevel(0);
|
||||||
|
isValid = true;
|
||||||
|
} catch (e) {}
|
||||||
|
assert(isValid);
|
||||||
|
done();
|
||||||
|
},
|
||||||
|
// PNG compression level - invalid
|
||||||
|
function(done) {
|
||||||
|
var isValid = false;
|
||||||
|
try {
|
||||||
|
sharp().compressionLevel(-1);
|
||||||
|
isValid = true;
|
||||||
|
} catch (e) {}
|
||||||
|
assert(!isValid);
|
||||||
|
done();
|
||||||
|
},
|
||||||
// Verify internal counters
|
// Verify internal counters
|
||||||
function(done) {
|
function(done) {
|
||||||
var counters = sharp.counters();
|
var counters = sharp.counters();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user