Apply correct forced output when chaining #1528

This commit is contained in:
Lovell Fuller 2019-01-01 18:40:09 +00:00
parent 813831acf0
commit 30ca424942
3 changed files with 17 additions and 1 deletions

View File

@ -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 - 7<sup>th</sup> December 2018
* Install: support `sharp_dist_base_url` npm config, like existing `SHARP_DIST_BASE_URL`.

View File

@ -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;
}

View File

@ -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()