From 30ca424942d4193154c291866bd52d1aebfd3570 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 1 Jan 2019 18:40:09 +0000 Subject: [PATCH] Apply correct forced output when chaining #1528 --- docs/changelog.md | 3 +++ lib/output.js | 4 +++- test/unit/io.js | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index a1491ebd..9e538e8f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -9,6 +9,9 @@ Requires libvips v8.7.0. * Prevent mutatation of options passed to `jpeg`. [#1516](https://github.com/lovell/sharp/issues/1516) +* Ensure forced output format applied correctly when output chaining. + [#1528](https://github.com/lovell/sharp/issues/1528) + #### v0.21.1 - 7th December 2018 * Install: support `sharp_dist_base_url` npm config, like existing `SHARP_DIST_BASE_URL`. diff --git a/lib/output.js b/lib/output.js index a3aad553..f74bfc35 100644 --- a/lib/output.js +++ b/lib/output.js @@ -541,7 +541,9 @@ function tile (tile) { * @returns {Sharp} */ function _updateFormatOut (formatOut, options) { - this.options.formatOut = (is.object(options) && options.force === false) ? 'input' : formatOut; + if (!(is.object(options) && options.force === false)) { + this.options.formatOut = formatOut; + } return this; } diff --git a/test/unit/io.js b/test/unit/io.js index 5392dbf7..2338501a 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -1376,6 +1376,17 @@ describe('Input/output', function () { }); }); + it('Can force output format with output chaining', function () { + return sharp(fixtures.inputJpg) + .resize(320, 240) + .png({ force: true }) + .jpeg({ force: false }) + .toBuffer({ resolveWithObject: true }) + .then(function (out) { + assert.strictEqual('png', out.info.format); + }); + }); + it('toFormat=JPEG takes precedence over WebP extension', function (done) { sharp(fixtures.inputPng) .jpeg()