Skip to content

Commit fcebab7

Browse files
committed
point GIFs in Image.decode() to Animation.decode()
1 parent 50ebe2b commit fcebab7

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
sizes in `renderText()` (which rendered an empty image); `maxPixels` that isn't positive in `Image.decode()` and
3737
`Animation.decode()` (which reported every image as too large); fractional loop counts in `new Animation()`.
3838
- `Animation.decode()` reports invalid `threads` and `maxPixels` as such, not as damaged image data.
39+
- `Image.decode()` refuses GIFs with a hint at `Animation.decode()` instead of "Unsupported image type".
3940

4041
## 3.13.2
4142

‎src/image.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@ export class Image {
22952295
if (ImageType.isPNM(dataView)) return netpbm.decode(data, maxPixels, toneMapping);
22962296
if (ImageType.isHDR(dataView)) return hdr.decode(data, maxPixels, toneMapping);
22972297
if (ImageType.isTGA(dataView)) return tga.decode(data, maxPixels);
2298+
if (ImageType.isGIF(dataView)) throw new Error('GIFs have to be decoded with Animation.decode() (or decode(), which returns an image or an animation)');
22982299
throw new Error('Unsupported image type');
22992300
});
23002301

‎tests/option-checks.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ const rejects = async (name, fn, Type, pattern) => {
6161
}
6262
await rejects('Animation.decode threads 0', () => Animation.decode(png, {threads: 0}), RangeError, /threads must be/);
6363

64+
// GIFs are refused by Image.decode() with a hint at Animation.decode()
65+
const gif = await new Animation([new Frame(4, 4).fill(0xff0000ff)]).encodeGIF();
66+
await rejects('Image.decode GIF', () => Image.decode(gif), Error, /Animation\.decode\(\)/);
67+
6468
// valid values keep working
6569
for (const effort of [0, 1, 2]) await image.encodeAVIF({effort});
6670
for (const subsampling of ['4:4:4', '4:2:0']) await image.encodeAVIF({quality: 50, subsampling});

0 commit comments

Comments
 (0)