Skip to content

Commit 4eda0a7

Browse files
matmenclaude
andcommitted
deprecate GIF in favor of Animation
GIF only adds encode() (encodeGIF), a decode() that accepts nothing but GIFs (Animation.decode) and its toString. It stays fully working in 3.x, editors show it as deprecated with the replacement; removal is planned for 4.0. Frame's documentation now talks about animations instead of GIFs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ljnxm1Qjrocq1izGajLx8J
1 parent 92f0b8e commit 4eda0a7

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
- **`Animation`**, the base class of `GIF`: an array of frames that decodes GIF and APNG (`Animation.decode()`) and
1111
encodes `encodeGIF()` and `encodeAPNG()`. `GIF` keeps its API.
1212

13+
### Deprecated
14+
15+
- **`GIF`**: use `Animation`, which works the same and also handles APNG (`new GIF(frames).encode()` becomes
16+
`new Animation(frames).encodeGIF()`, `GIF.decode()` becomes `Animation.decode()`). `GIF` will be removed in 4.0.
17+
1318
## 3.0.0
1419

1520
ImageScript is now written in TypeScript and has no WebAssembly or native binaries anymore. Every codec and renderer

‎src/frame.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
import { Image, ResizeMode } from './image.ts';
22

3-
/** Names of the GIF frame disposal modes, see {@link Frame.disposalMode} */
3+
/** Names of the frame disposal modes, see {@link Frame.disposalMode} */
44
export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
5-
/** Ids of the GIF frame disposal modes as stored in the file (0 any, 1 keep, 2 previous, 3 background) */
5+
/** Ids of the frame disposal modes, as GIFs store them (0 any, 1 keep, 2 previous, 3 background) */
66
export type FrameDisposalModeId = 0 | 1 | 2 | 3;
77

88
const DISPOSAL_MODES: readonly FrameDisposalModeName[] = ['any', 'keep', 'previous', 'background'];
99

1010
/**
11-
* Represents a frame in a GIF
11+
* Represents a frame of an {@link Animation}
1212
*/
1313
export class Frame extends Image {
1414
/**
15-
* Milliseconds. GIFs store hundredths of a second, so this is rounded to 10 ms when encoding;
15+
* Milliseconds. GIFs store hundredths of a second, so this is rounded to 10 ms when encoding a GIF;
1616
* note that browsers play frames shorter than 20 ms with 100 ms
1717
*/
1818
duration: number;
19-
/** The frame's horizontal offset in the GIF */
19+
/** The frame's horizontal offset in the animation */
2020
xOffset: number;
21-
/** The frame's vertical offset in the GIF */
21+
/** The frame's vertical offset in the animation */
2222
yOffset: number;
2323
/** @internal */
2424
private __disposalMode__: FrameDisposalModeId = 1;
2525

26-
/** GIF frame disposal mode ANY: the decoder decides (in practice like KEEP). For use with {@link Frame} */
26+
/** Frame disposal mode ANY: the decoder decides (in practice like KEEP). For use with {@link Frame} */
2727
static get DISPOSAL_ANY(): 'any' {
2828
return 'any';
2929
}
3030

31-
/** GIF frame disposal mode KEEP. For use with {@link Frame} */
31+
/** Frame disposal mode KEEP. For use with {@link Frame} */
3232
static get DISPOSAL_KEEP(): 'keep' {
3333
return 'keep';
3434
}
3535

36-
/** GIF frame disposal mode PREVIOUS. For use with {@link Frame} */
36+
/** Frame disposal mode PREVIOUS. For use with {@link Frame} */
3737
static get DISPOSAL_PREVIOUS(): 'previous' {
3838
return 'previous';
3939
}
4040

41-
/** GIF frame disposal mode BACKGROUND. For use with {@link Frame} */
41+
/** Frame disposal mode BACKGROUND. For use with {@link Frame} */
4242
static get DISPOSAL_BACKGROUND(): 'background' {
4343
return 'background';
4444
}

‎src/gif.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Animation } from './animation.ts';
66
/**
77
* Represents a GIF image as an array of frames, an {@link Animation} whose `encode()` and `decode()` work with GIFs.
88
* Array methods like map and filter return plain arrays.
9+
* @deprecated Use {@link Animation}, which works the same and also handles APNG: `new Animation(frames, loopCount)`,
10+
* {@link Animation.decode} and {@link Animation.encodeGIF}. `GIF` will be removed in 4.0
911
*/
1012
export class GIF extends Animation {
1113
/**
@@ -24,6 +26,7 @@ export class GIF extends Animation {
2426
/**
2527
* Encodes the GIF
2628
* @param quality 1-100, scales the palette size from 8 colors (1) to 256 colors (90 and above)
29+
* @deprecated Use {@link Animation.encodeGIF}
2730
*/
2831
async encode(quality = 95): Promise<Uint8Array> {
2932
return this.encodeGIF(quality);
@@ -33,6 +36,7 @@ export class GIF extends Animation {
3336
* Decodes a GIF into fully composited frames
3437
* @param input The binary data to decode
3538
* @param onlyExtractFirstFrame Whether to end GIF decoding after the first frame
39+
* @deprecated Use {@link Animation.decode}, which decodes APNGs too
3640
*/
3741
static override async decode(input: BinaryData, onlyExtractFirstFrame = false): Promise<GIF> {
3842
const data = view(input);

‎src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type { ImageTypeName } from './image-type.ts';
1616
export type { BinaryData } from './util/mem.ts';
1717

1818
/**
19-
* Decodes any supported image: GIFs are returned as {@link GIF}, everything else (including APNGs, as their default
20-
* image) as {@link Image}. {@link Animation.decode} decodes the frames of APNGs
19+
* Decodes any supported image: GIFs are returned as {@link GIF} (an {@link Animation}), everything else (including
20+
* APNGs, as their default image) as {@link Image}. {@link Animation.decode} decodes the frames of GIFs and APNGs
2121
* @param data The image data
2222
* @param onlyExtractFirstFrame Whether to end animation decoding after the first frame
2323
*/

0 commit comments

Comments
 (0)