diff --git a/src/pipeline.cc b/src/pipeline.cc index 23988535..cc38cef7 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -72,7 +72,9 @@ class PipelineWorker : public Napi::AsyncWorker { int nPages = baton->input->pages; if (nPages == -1) { // Resolve the number of pages if we need to render until the end of the document - nPages = image.get_typeof(VIPS_META_N_PAGES) != 0 ? image.get_int(VIPS_META_N_PAGES) : 1; + nPages = image.get_typeof(VIPS_META_N_PAGES) != 0 + ? image.get_int(VIPS_META_N_PAGES) - baton->input->page + : 1; } // Get pre-resize page height diff --git a/test/unit/webp.js b/test/unit/webp.js index 3e122e8b..f87f3caf 100644 --- a/test/unit/webp.js +++ b/test/unit/webp.js @@ -217,4 +217,15 @@ describe('WebP', function () { assert.strictEqual(updated.height, 570 * 9); assert.strictEqual(updated.pageHeight, 570); }); + + it('should take page parameter into account when animated is set', async () => { + const updated = await sharp(fixtures.inputWebPAnimated, { animated: true, page: 2 }) + .resize({ height: 570 }) + .webp({ effort: 0 }) + .toBuffer() + .then(data => sharp(data, { pages: -1 }).metadata()); + + assert.strictEqual(updated.height, 570 * 7); + assert.strictEqual(updated.pageHeight, 570); + }); });