mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add pageHeight param to create/new for animated input #3236
This commit is contained in:
@@ -418,6 +418,7 @@ sharp({
|
||||
channels: 4,
|
||||
height: 25000,
|
||||
width: 25000,
|
||||
pageHeight: 1000,
|
||||
},
|
||||
limitInputPixels: false,
|
||||
})
|
||||
@@ -734,6 +735,13 @@ sharp({ svg: { stylesheet: 'test' }});
|
||||
sharp({ svg: { highBitdepth: true }});
|
||||
sharp({ svg: { highBitdepth: false }});
|
||||
|
||||
// Raw input options
|
||||
const raw: sharp.Raw = { width: 1, height: 1, channels: 3 };
|
||||
sharp({ raw });
|
||||
sharp({ raw: { ...raw, premultiplied: true } });
|
||||
sharp({ raw: { ...raw, premultiplied: false } });
|
||||
sharp({ raw: { ...raw, pageHeight: 1 } });
|
||||
|
||||
sharp({ autoOrient: true });
|
||||
sharp({ autoOrient: false });
|
||||
sharp().autoOrient();
|
||||
|
||||
@@ -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/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,6 +55,35 @@ describe('Raw pixel data', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid premultiplied', () => {
|
||||
assert.throws(
|
||||
() => sharp({ raw: { width: 1, height: 1, channels: 4, premultiplied: 'zoinks' } }),
|
||||
/Expected boolean for raw\.premultiplied but received zoinks of type string/
|
||||
);
|
||||
});
|
||||
|
||||
it('Invalid pageHeight', () => {
|
||||
const width = 8;
|
||||
const height = 8;
|
||||
const channels = 4;
|
||||
assert.throws(
|
||||
() => sharp({ raw: { width, height, channels, pageHeight: 'zoinks' } }),
|
||||
/Expected positive integer for raw\.pageHeight but received zoinks of type string/
|
||||
);
|
||||
assert.throws(
|
||||
() => sharp({ raw: { width, height, channels, pageHeight: -1 } }),
|
||||
/Expected positive integer for raw\.pageHeight but received -1 of type number/
|
||||
);
|
||||
assert.throws(
|
||||
() => sharp({ raw: { width, height, channels, pageHeight: 9 } }),
|
||||
/Expected positive integer for raw\.pageHeight but received 9 of type number/
|
||||
);
|
||||
assert.throws(
|
||||
() => sharp({ raw: { width, height, channels, pageHeight: 3 } }),
|
||||
/Expected raw\.height 8 to be a multiple of raw\.pageHeight 3/
|
||||
);
|
||||
});
|
||||
|
||||
it('RGB', function (done) {
|
||||
// Convert to raw pixel data
|
||||
sharp(fixtures.inputJpg)
|
||||
@@ -285,6 +314,23 @@ describe('Raw pixel data', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('Animated', async () => {
|
||||
const gif = await sharp(
|
||||
Buffer.alloc(8),
|
||||
{ raw: { width: 1, height: 2, channels: 4, pageHeight: 1 }, animated: true }
|
||||
)
|
||||
.gif({ keepDuplicateFrames: true })
|
||||
.toBuffer();
|
||||
|
||||
console.log(await sharp(gif).metadata());
|
||||
|
||||
const { width, height, pages, delay } = await sharp(gif).metadata();
|
||||
assert.strictEqual(width, 1);
|
||||
assert.strictEqual(height, 1);
|
||||
assert.strictEqual(pages, 2);
|
||||
assert.strictEqual(delay.length, 2);
|
||||
});
|
||||
|
||||
describe('16-bit roundtrip', () => {
|
||||
it('grey', async () => {
|
||||
const grey = 42000;
|
||||
|
||||
Reference in New Issue
Block a user