diff --git a/docs/api-resize.md b/docs/api-resize.md index e95ea315..5b84b1e3 100644 --- a/docs/api-resize.md +++ b/docs/api-resize.md @@ -214,7 +214,7 @@ Extract/crop a region of the image. - Use `extract` before `resize` for pre-resize extraction. - Use `extract` after `resize` for post-resize extraction. -- Use `extract` before and after for both. +- Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order. **Throws**: diff --git a/lib/resize.js b/lib/resize.js index 6677dba7..e5e3b146 100644 --- a/lib/resize.js +++ b/lib/resize.js @@ -250,6 +250,9 @@ function resize (widthOrOptions, height, options) { if (isResizeExpected(this.options)) { this.options.debuglog('ignoring previous resize options'); } + if (this.options.widthPost !== -1) { + this.options.debuglog('operation order will be: extract, resize, extract'); + } if (is.defined(widthOrOptions)) { if (is.object(widthOrOptions) && !is.defined(options)) { options = widthOrOptions; @@ -437,7 +440,7 @@ function extend (extend) { * * - Use `extract` before `resize` for pre-resize extraction. * - Use `extract` after `resize` for post-resize extraction. - * - Use `extract` before and after for both. + * - Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order. * * @example * sharp(input) diff --git a/test/unit/extract.js b/test/unit/extract.js index 760e90ef..c2eae90b 100644 --- a/test/unit/extract.js +++ b/test/unit/extract.js @@ -319,5 +319,16 @@ describe('Partial image extraction', function () { s.extract(options); assert.strictEqual(warningMessage, 'ignoring previous extract options'); }); + + it('Multiple extract+resize emits warning', () => { + let warningMessage = ''; + const s = sharp(); + s.on('warning', function (msg) { warningMessage = msg; }); + const options = { top: 0, left: 0, width: 1, height: 1 }; + s.extract(options).extract(options); + assert.strictEqual(warningMessage, ''); + s.resize(1); + assert.strictEqual(warningMessage, 'operation order will be: extract, resize, extract'); + }); }); });