Add pageHeight param to create/new for animated input #3236

This commit is contained in:
Lovell Fuller
2025-06-21 11:33:52 +01:00
parent 852c7f8663
commit e26d4e9d5b
11 changed files with 179 additions and 20 deletions

View File

@@ -173,6 +173,26 @@ describe('Gaussian noise', function () {
});
});
it('animated noise', async () => {
const gif = await sharp({
create: {
width: 16,
height: 64,
pageHeight: 16,
channels: 3,
noise: { type: 'gaussian' }
}
})
.gif()
.toBuffer();
const { width, height, pages, delay } = await sharp(gif).metadata();
assert.strictEqual(width, 16);
assert.strictEqual(height, 16);
assert.strictEqual(pages, 4);
assert.strictEqual(delay.length, 4);
});
it('no create object properties specified', function () {
assert.throws(function () {
sharp({
@@ -259,4 +279,29 @@ describe('Gaussian noise', function () {
});
});
});
it('Invalid pageHeight', () => {
const create = {
width: 8,
height: 8,
channels: 4,
noise: { type: 'gaussian' }
};
assert.throws(
() => sharp({ create: { ...create, pageHeight: 'zoinks' } }),
/Expected positive integer for create\.pageHeight but received zoinks of type string/
);
assert.throws(
() => sharp({ create: { ...create, pageHeight: -1 } }),
/Expected positive integer for create\.pageHeight but received -1 of type number/
);
assert.throws(
() => sharp({ create: { ...create, pageHeight: 9 } }),
/Expected positive integer for create\.pageHeight but received 9 of type number/
);
assert.throws(
() => sharp({ create: { ...create, pageHeight: 3 } }),
/Expected create\.height 8 to be a multiple of create\.pageHeight 3/
);
});
});