Make compressionLevel/quality configurable + change defaults
This commit is contained in:
parent
074c873826
commit
5a94689385
2 changed files with 19 additions and 4 deletions
|
@ -43,7 +43,12 @@ The config file can contain definition of several paths where the tiles will be
|
||||||
"domains": [
|
"domains": [
|
||||||
"localhost:8080",
|
"localhost:8080",
|
||||||
"127.0.0.1:8080"
|
"127.0.0.1:8080"
|
||||||
]
|
],
|
||||||
|
"formatEncoding": {
|
||||||
|
"png": 6,
|
||||||
|
"jpeg": 80,
|
||||||
|
"webp": 90
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"styles": {
|
"styles": {
|
||||||
"test": {
|
"test": {
|
||||||
|
|
|
@ -230,9 +230,19 @@ module.exports = function(options, repo, params, id) {
|
||||||
image.resize(width * scale, height * scale);
|
image.resize(width * scale, height * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
image.toFormat(format)
|
image.toFormat(format);
|
||||||
.compressionLevel(9)
|
|
||||||
.toBuffer(function(err, buffer, info) {
|
var formatEncoding = (params.formatEncoding || {})[format] ||
|
||||||
|
(options.formatEncoding || {})[format];
|
||||||
|
if (format == 'png') {
|
||||||
|
image.compressionLevel(formatEncoding || 6)
|
||||||
|
.withoutAdaptiveFiltering();
|
||||||
|
} else if (format == 'jpeg') {
|
||||||
|
image.quality(formatEncoding || 80);
|
||||||
|
} else if (format == 'webp') {
|
||||||
|
image.quality(formatEncoding || 90);
|
||||||
|
}
|
||||||
|
image.toBuffer(function(err, buffer, info) {
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
return res.status(404).send('Not found');
|
return res.status(404).send('Not found');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue