Skip to content

Commit ccf090b

Browse files
committed
Merge remote-tracking branch 'old-origin/master' into jim-merge # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
2 parents e414d43 + 14e94fb commit ccf090b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

source/new-image-handler/src/processor/image/interlace.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export class InterlaceAction implements IImageAction {
2626

2727
public async process(ctx: IImageContext, params: string[]): Promise<void> {
2828
const opt = this.validate(params);
29-
if (opt.interlace) {
29+
const metadata = await ctx.image.metadata();
30+
if (('jpg' === metadata.format || 'jpeg' === metadata.format) && opt.interlace) {
3031
ctx.image.jpeg({ progressive: true });
3132
}
32-
3333
}
3434
}

source/new-image-handler/test/processor/image/interlace.test.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('Interlace action validate', () => {
3333
});
3434

3535

36-
test('quality action', async () => {
36+
test('interlace,1', async () => {
3737
const image = sharp((await fixtureStore.get('example.jpg')).buffer);
3838
const ctx: IImageContext = { image, bufferStore: fixtureStore, features: {} };
3939
const action = new InterlaceAction();
@@ -43,11 +43,24 @@ test('quality action', async () => {
4343
});
4444

4545

46-
test('quality action', async () => {
46+
test('interlace,0', async () => {
4747
const image = sharp((await fixtureStore.get('example.jpg')).buffer);
4848
const ctx: IImageContext = { image, bufferStore: fixtureStore, features: {} };
4949
const action = new InterlaceAction();
5050
await action.process(ctx, 'interlace,0'.split(','));
5151
const { info } = await ctx.image.toBuffer({ resolveWithObject: true });
5252
expect(info.format).toBe(sharp.format.jpeg.id);
53+
});
54+
55+
test('interlace,1 for gif', async () => {
56+
const image = sharp((await fixtureStore.get('example.gif')).buffer, { animated: true });
57+
const ctx: IImageContext = { image, bufferStore: fixtureStore, features: {} };
58+
const action = new InterlaceAction();
59+
await action.process(ctx, 'interlace,1'.split(','));
60+
const { data, info } = await ctx.image.toBuffer({ resolveWithObject: true });
61+
62+
expect(info.format).toBe(sharp.format.gif.id);
63+
64+
const metadata = await sharp(data, { animated: true }).metadata();
65+
expect(metadata.pages).toBe(3);
5366
});

0 commit comments

Comments
 (0)