Skip to content

Commit 64ab0be

Browse files
committed
Audit v4 migration documentation
1 parent 7b73444 commit 64ab0be

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Breaking changes
66

7-
Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation hints, then switch: the [migration guide](https://imagescript.dev/documents/Migrating_to_4.0.html) lists every change and the nine behavior changes that don't show up as deprecations or compile errors.
7+
Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation hints, then switch: the [migration guide](https://imagescript.dev/documents/Migrating_to_4.0.html) covers the 3.x-to-4.0 API changes and the nine behavior changes that don't show up as deprecations or compile errors.
88

99
- **Methods that take options refuse anything else than an object**: a stray number, string, boolean or `null` as the options of `cropCircle()`, `Image.renderText()`, the encoders (`encodeWebP()`, `encodeAVIF()`, `encodeJXL()`, ...), `quantize()`, `transform()`, `dropShadow()`, `outline()`, the gradients, `Image.decode()`, the animation encoders, and `new GainMap()` throws a `TypeError` that names the working form (e.g. `cropCircle({ size: 'cover' })`), so the 3.x calls that are gone like `cropCircle(true)` or `Image.renderText(font, 32, 'Hi')` fail instead of being ignored. Only the type of the argument is checked: a key that isn't an option is still ignored, so a typo like `{ maxWith: 300 }` isn't caught.
1010

@@ -14,7 +14,7 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
1414

1515
- **`Image.encode()` is removed**: use `image.encodePNG()`, which takes the same arguments.
1616

17-
- **`contain()` and `cover()` are removed** from `Image`, `Frame` and `Animation`: use `resize({ width, height, fit: 'contain' | 'cover' })`. `fit: 'contain'` also takes `background`; `ResizeFit` names the fit modes and `ContainOptions` is removed. 3.x's `contain()` maps to `'inside'`, and 3.x's padded `fit()` maps to `'contain'`.
17+
- **`contain()` and `cover()` are removed** from `Image`, `Frame` and `Animation`: use `resize({ width, height, fit: 'contain' })` or `resize({ width, height, fit: 'cover' })`. `fit: 'contain'` also takes `background`; `ResizeFit` names the fit modes and `ContainOptions` is removed. 3.x's `contain()` maps to `'inside'`, and 3.x's padded `fit()` maps to `'contain'`.
1818

1919
- **The color helpers of `Image` are removed**: `Image.rgbaToColor()`, `Image.rgbToColor()`, `Image.hslaToColor()`, `Image.hslToColor()`, `Image.rgbaToHSLA()`, `Image.colorToRGBA()`, `Image.colorToRGB()` and `Image.gradient()` are now `Colors.fromRGBA()`, `Colors.fromRGB()`, `Colors.fromHSLA()`, `Colors.fromHSL()`, `Colors.toHSLA()`, `Colors.toRGBA()`, `Colors.toRGB()` and `Colors.gradient()`.
2020

@@ -86,18 +86,18 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
8686

8787
- **Values are checked when they are set**: `frame.duration`, `frame.xOffset`, `frame.yOffset` and the parameters of a `GainMap` throw for invalid values (instead of failing in a later encode) and keep their value.
8888

89-
- **An animation has its own canvas size**: decoded animations keep the file's, `new Animation(frames, { width, height })` sets one, and `resize()` sets the new one. Without one it is the frames' extent, as before. Frames (or their parts) outside the canvas aren't encoded.
89+
- **An animation has its own canvas size**: decoded animations keep the file's, `new Animation(frames, { width, height })` sets one (`AnimationCanvasOptions`), and `resize()` sets the new one. Without one it is the frames' extent, as before. Frames (or their parts) outside the canvas aren't encoded.
9090

9191
- **The encoders return `Promise<Uint8Array<ArrayBuffer>>`** instead of `Promise<Uint8Array>`, so `new Blob()`, `new Response()` and `crypto.subtle` take the output without a cast, also with the stricter DOM types of TypeScript 5.9 and newer. The type needs TypeScript 5.7 or newer.
9292

9393
### New
9494

9595
- `Animation.clone()` and `Animation.crop()`.
9696
- `resize({ width, height, fit })` on images, frames and animations: `'inside'` fits without padding, `'contain'` pads, and `'cover'` crops while keeping the aspect ratio; `background` sets the bars for `'contain'`.
97-
- `encodeJPEG({ subsampling: '4:4:4' | '4:2:0' })`; the default stays 4:2:0 up to quality 90 and 4:4:4 above.
97+
- `encodeJPEG()` accepts `subsampling: '4:4:4'` or `'4:2:0'`; the default stays 4:2:0 up to quality 90 and 4:4:4 above.
9898
- `Colors.gradient()` takes an array of evenly spaced colors, like the `stops` of the gradient functions.
9999
- `Animation.scale()`, `Animation.trim()`, `Animation.rotate()`, `Animation.transform()`, `Animation.dropShadow()` and `Animation.outline()`. `scale()` and `trim()` keep the frames; the others work on the composited animation (full canvas frames) and resize the canvas.
100-
- `'contain'` and `'cover'` fit modes of `Frame.resize()`, plus `Frame.rotate()`, `Frame.transform()`, `Frame.dropShadow()` and `Frame.outline()`, which move the offsets like `Frame.resize()` and `Frame.crop()`.
100+
- `Frame.rotate()`, `Frame.transform()`, `Frame.dropShadow()` and `Frame.outline()`, which move the offsets like `Frame.resize()` and `Frame.crop()`.
101101
- `Image.encodeGIF()` for single images, with `colors`, `dither` and `ditherStrength` (also on the animation encoders), and the `DitherMethod` type that `quantize()` and the GIF encoders share.
102102
- `renderSVG({ fonts })` takes a single font without an array.
103103

‎guides/Migrating to 4.0.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ animations; frame offsets and animation canvases follow the resized pixels.
124124
| `'contain'` | Keeps the aspect ratio and pads to the exact box; `background` sets the bar color |
125125
| `'cover'` | Keeps the aspect ratio and crops to the exact box |
126126

127-
`contain` and `cover` require both dimensions. `background` is only valid with `fit: 'contain'`.
127+
`contain` and `cover` require both dimensions. `background` is only valid with `fit: 'contain'`. `ResizeFit` is the
128+
type of the `fit` option.
128129

129130
| 3.x | 4.0 |
130131
| --- | --- |
@@ -161,6 +162,8 @@ JPEG has no alpha channel. In 3.x, `encodeJPEG()` dropped the alpha and kept the
161162
showed whatever RGB it had stored (often black, but not always). In 4.0, an image with transparent or translucent pixels
162163
is composited onto a background first, black by default, the way a viewer would show it on black. Pass `background`
163164
for another color: `image.encodeJPEG({ background: 0xffffffff })`. Opaque images encode as before, byte for byte.
165+
The new `subsampling` option can select `'4:4:4'` or `'4:2:0'`; its default remains 4:2:0 up to quality 90 and 4:4:4
166+
above.
164167

165168
Search your code for: `encodeJPEG(` on images that can have transparency.
166169

@@ -244,8 +247,9 @@ any more, so `image.resize(256, 256, { mode: 'RESIZE_BICUBIC' })` throws.
244247
| `for (const [x, y] of image)` | `for (const [x, y] of image.coordinates())` |
245248
| `image.iterateWithColors()` | `image.pixels()`, which yields `[x, y, color]` |
246249

247-
The color helpers take the same arguments and return the same values, so `Image.rgbaToColor(...)` becomes
248-
`Colors.fromRGBA(...)` and nothing else changes. `Colors` is exported from the package.
250+
The moved color helpers keep their argument shapes and results, except for the hue-unit change described above.
251+
`Colors.gradient()` also accepts an array of evenly spaced colors, in addition to the prior positions-to-colors object.
252+
`Colors` is exported from the package.
249253

250254
### Channel methods and `absolute`
251255

@@ -434,7 +438,7 @@ Values that were only checked when they were used are now checked when they are
434438
throws a `RangeError` (a `TypeError` for `useBaseColorSpace`) and the old value stays.
435439

436440
An `Animation` now has a canvas size of its own: `animation.width` and `animation.height` are the decoded file's, the
437-
one given as `new Animation(frames, { width, height })`, or the one `resize()` and `crop()` set.
441+
one given as `new Animation(frames, { width, height })` (`AnimationCanvasOptions`), or the one `resize()` and `crop()` set.
438442
Without one, they are the frames' right and bottom edge, as in 3.x. Frames, or the parts of them, outside the canvas
439443
aren't encoded.
440444

0 commit comments

Comments
 (0)