Skip to content

Commit c4d74ed

Browse files
authored
Ensure info.pages is correct when limiting input page range (#4578)
1 parent 56676c6 commit c4d74ed

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/common.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,12 @@ namespace sharp {
711711
bool hasDelay = !delay.empty();
712712
VImage copy = image.copy();
713713

714-
// Only set page-height if we have more than one page, or this could
715-
// accidentally turn into an animated image later.
716-
if (nPages > 1) copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
714+
// Only set page-height and n-pages if we have more than one page, or this
715+
// could accidentally turn into an animated image later.
716+
if (nPages > 1) {
717+
copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
718+
copy.set(VIPS_META_N_PAGES, nPages);
719+
}
717720
if (hasDelay) {
718721
if (delay.size() == 1) {
719722
// We have just one delay, repeat that value for all frames.

test/unit/gif.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ suite('GIF input', () => {
6464
t.assert.strictEqual(80, info.pageHeight);
6565
});
6666

67+
test('Animated GIF limited to fewer pages than the input', async (t) => {
68+
t.plan(3);
69+
const { info } = await sharp(fixtures.inputGifAnimated, { pages: 2 }).toBuffer({ resolveWithObject: true });
70+
t.assert.strictEqual(160, info.height);
71+
t.assert.strictEqual(80, info.pageHeight);
72+
t.assert.strictEqual(2, info.pages);
73+
});
74+
6775
test('GIF with reduced colours, no dither, low effort reduces file size', async (t) => {
6876
t.plan(1);
6977
const original = await sharp(fixtures.inputJpg)

0 commit comments

Comments
 (0)