From 5a946893850b9e33999177bdb53f282117a0b008 Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Fri, 11 Mar 2016 16:40:05 +0100 Subject: [PATCH] Make compressionLevel/quality configurable + change defaults --- README.md | 7 ++++++- src/serve_raster.js | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d44b187..306cf55 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,12 @@ The config file can contain definition of several paths where the tiles will be "domains": [ "localhost:8080", "127.0.0.1:8080" - ] + ], + "formatEncoding": { + "png": 6, + "jpeg": 80, + "webp": 90 + } }, "styles": { "test": { diff --git a/src/serve_raster.js b/src/serve_raster.js index a32fcb4..ead1f56 100644 --- a/src/serve_raster.js +++ b/src/serve_raster.js @@ -230,9 +230,19 @@ module.exports = function(options, repo, params, id) { image.resize(width * scale, height * scale); } - image.toFormat(format) - .compressionLevel(9) - .toBuffer(function(err, buffer, info) { + image.toFormat(format); + + 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) { return res.status(404).send('Not found'); }