Skip to content

Commit c4a3e53

Browse files
committed
docs: refactor Images part and explain more breaking changes
1 parent fd3597a commit c4a3e53

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

blog/release.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ This eliminates runtime type errors and provides better IntelliSense, autocomple
2626

2727
## ⚠️ Breaking changes
2828

29-
### Loading and saving images
29+
### Images
30+
31+
#### Loading and saving
3032

3133
`load()` and `save()` have been replaced with dedicated functions `read()` and `write()`.
3234

@@ -54,7 +56,7 @@ writeSync('newCat.jpg', img);
5456

5557
The new approach allows for better TypeScript inference, smaller bundle sizes through tree-shaking, and clearer API design where I/O operations are separate from image manipulation.
5658

57-
### Creating images
59+
#### Creating
5860

5961
When creating a new image, unlike before, image's width and height must be specified.
6062

@@ -69,6 +71,20 @@ const image2 = new Image(10, 10);
6971

7072
This change makes the Image constructor more explicit by requiring you to specify the dimensions upfront, preventing potential errors from working with uninitialized or undefined-sized images
7173

74+
#### Image position
75+
76+
Images now include an `origin` property that tracks their position relative to their parent image. When you crop an image, the cropped section remembers where it came from in the original image.
77+
78+
```ts
79+
const croppedImage = img.crop({
80+
origin: { column: 10, row: 10 },
81+
width: 10,
82+
height: 10,
83+
});
84+
85+
console.log(croppedImage.origin); // { column: 10, row: 10 }
86+
```
87+
7288
### Masks
7389

7490
Binary images are now handled by a dedicated `Mask` class instead of Image with `kind: 'BINARY'`.
@@ -87,6 +103,27 @@ const mask = new Mask(10, 10);
87103

88104
The new `Mask` class uses 1 byte per pixel (vs 8 pixels per byte), trading ~8x memory usage for significantly faster bit operations and simpler data manipulation.
89105

106+
### Points
107+
108+
Coordinates are now represented using `Point` objects instead of arrays. This change affects methods that require coordinate input like cropping, drawing, and pixel manipulation.
109+
110+
```ts
111+
// Before
112+
const croppedImage = img.crop({
113+
origin: [10, 10],
114+
width: 10,
115+
height: 10,
116+
});
117+
// After
118+
const croppedImage = img.crop({
119+
origin: { column: 10, row: 10 },
120+
width: 10,
121+
height: 10,
122+
});
123+
```
124+
125+
It is a more explicit and self-documenting code and it also eliminates confusion about array order (column vs row).
126+
90127
### Sobel and Scharr filters
91128

92129
[Sobel](https://en.wikipedia.org/wiki/Sobel_operator), [Scharr](https://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators) filters are now combined into a single `derivative()` method.
@@ -143,12 +180,12 @@ The following deprecated features have been removed:
143180
- `countAlphaPixel()` - Use custom pixel counting with `getPixel()`
144181
- `paintLabels()` - Feature was removed due to dependency issues. We plan to add it back in the future updates.
145182
- `warpingFourPoints()` - Use `getPerspectiveWarp()` + `transform()`.
146-
- 32-bit color depth has been currently deprecated. We plan to add it back in the future updates as well.
147-
- `CMYK` and `HSL` color models have been deprecated. We plan to add it in the future updates.
148-
- `insert()` has been deprecated. We plan to add it in the future updates.
149-
- `abs()` has been deprecated. Currently 32-bit images are not supported.
150-
- `paintMasks()` has been deprecated. Use `paintMask()`+ `for` loop.
151-
- `mergeRois()` has been deprecated. We plan to add it in the future updates.
183+
- 32-bit color depth has been currently removed. We plan to add it back in the future updates as well.
184+
- `CMYK` and `HSL` color models have been removed.
185+
- `insert()` has been removed.
186+
- `abs()` has been removed.
187+
- `paintMasks()` has been removed. Use `paintMask()`+ `for` loop.
188+
- `mergeRois()` has been removed.
152189

153190
## 🆕 New Features
154191

0 commit comments

Comments
 (0)