@rosepetal/node-red-contrib-image-tools 1.6.4 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.claude/rules/node-implementation-template.md +1 -1
  2. package/.github/workflows/build-prebuild.yml +1 -1
  3. package/README.md +41 -21
  4. package/docs/index.md +156 -0
  5. package/docs/nodes/blend/add-bbs.md +116 -0
  6. package/docs/nodes/blend/add-mask.md +67 -224
  7. package/docs/nodes/blend/add-masks.md +74 -196
  8. package/docs/nodes/blend/blend.md +84 -200
  9. package/docs/nodes/io/folder-in.md +92 -0
  10. package/docs/nodes/io/image-in.md +61 -52
  11. package/docs/nodes/io/image-out.md +114 -93
  12. package/docs/nodes/mix/advanced-mosaic.md +124 -78
  13. package/docs/nodes/mix/concat.md +71 -56
  14. package/docs/nodes/mix/mosaic.md +81 -91
  15. package/docs/nodes/specialized/cropBB.md +76 -214
  16. package/docs/nodes/specialized/heat-diff.md +111 -0
  17. package/docs/nodes/specialized/image-align.md +125 -387
  18. package/docs/nodes/transform/color-convert.md +101 -0
  19. package/docs/nodes/transform/crop.md +56 -58
  20. package/docs/nodes/transform/draw.md +46 -26
  21. package/docs/nodes/transform/filter.md +110 -46
  22. package/docs/nodes/transform/padding.md +55 -55
  23. package/docs/nodes/transform/resize.md +81 -56
  24. package/docs/nodes/transform/rotate.md +67 -50
  25. package/node-red-contrib-image-tools/lib/bmp-decode.js +18 -68
  26. package/node-red-contrib-image-tools/lib/cpp-bridge.js +202 -104
  27. package/node-red-contrib-image-tools/lib/node-utils.js +78 -78
  28. package/node-red-contrib-image-tools/nodes/io/folder-in.js +98 -46
  29. package/node-red-contrib-image-tools/nodes/io/image-in.js +3 -4
  30. package/node-red-contrib-image-tools/nodes/io/image-out.js +93 -146
  31. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +3 -3
  32. package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +3 -3
  33. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
  34. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +5 -4
  35. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +3 -3
  36. package/node-red-contrib-image-tools/nodes/transform/crop.js +3 -3
  37. package/node-red-contrib-image-tools/nodes/transform/filter.js +3 -3
  38. package/node-red-contrib-image-tools/nodes/transform/padding.js +3 -3
  39. package/node-red-contrib-image-tools/nodes/transform/resize.js +3 -3
  40. package/node-red-contrib-image-tools/nodes/transform/rotate.js +3 -3
  41. package/npm/darwin-arm64/package.json +1 -1
  42. package/npm/darwin-x64/package.json +1 -1
  43. package/npm/linux-arm64/package.json +1 -1
  44. package/npm/linux-x64/package.json +1 -1
  45. package/npm/linuxmusl-x64/package.json +1 -1
  46. package/npm/win32-x64/package.json +1 -1
  47. package/package.json +6 -6
  48. package/rosepetal-image-engine/binding.gyp +2 -1
  49. package/rosepetal-image-engine/src/add-bbs.cpp +123 -123
  50. package/rosepetal-image-engine/src/add-mask.cpp +30 -15
  51. package/rosepetal-image-engine/src/add-masks.cpp +145 -102
  52. package/rosepetal-image-engine/src/advanced-mosaic.cpp +200 -129
  53. package/rosepetal-image-engine/src/blend.cpp +34 -20
  54. package/rosepetal-image-engine/src/codec.cpp +157 -0
  55. package/rosepetal-image-engine/src/color-convert.cpp +22 -19
  56. package/rosepetal-image-engine/src/concat.cpp +38 -43
  57. package/rosepetal-image-engine/src/crop.cpp +23 -26
  58. package/rosepetal-image-engine/src/draw.cpp +33 -10
  59. package/rosepetal-image-engine/src/filter.cpp +22 -26
  60. package/rosepetal-image-engine/src/heat-diff.cpp +35 -8
  61. package/rosepetal-image-engine/src/image-align.cpp +107 -35
  62. package/rosepetal-image-engine/src/main.cpp +4 -0
  63. package/rosepetal-image-engine/src/mosaic.cpp +31 -40
  64. package/rosepetal-image-engine/src/padding.cpp +30 -29
  65. package/rosepetal-image-engine/src/resize.cpp +20 -25
  66. package/rosepetal-image-engine/src/rotate.cpp +22 -23
  67. package/rosepetal-image-engine/src/utils.h +243 -144
  68. package/scripts/build-opencv-static.sh +6 -0
  69. package/scripts/dual-register.js +32 -25
  70. package/scripts/sync-version.js +58 -41
@@ -1,8 +1,23 @@
1
+ ---
2
+ title: "Padding Node - Add Margins Around Images"
3
+ description: "Add top, bottom, left and right margins of a solid color around images in Node-RED. Part of @rosepetal/node-red-contrib-image-tools."
4
+ head:
5
+ - - meta
6
+ - name: "keywords"
7
+ content: "node-red, padding, margin, border, canvas, opencv, rosepetal"
8
+ - - meta
9
+ - property: "og:title"
10
+ content: "Padding Node - @rosepetal/node-red-contrib-image-tools"
11
+ - - meta
12
+ - property: "og:description"
13
+ content: "Add top, bottom, left and right margins of a solid color around images in Node-RED."
14
+ ---
15
+
1
16
  # Padding Node
2
17
 
3
18
  ## Purpose & Use Cases
4
19
 
5
- The `padding` node adds margins around images with configurable colors and dimensions. It expands the canvas size while preserving the original image content, perfect for creating borders, standardizing dimensions, or preparing images for specific layouts.
20
+ The `padding` node adds a margin of a solid colour on each side of an image, or of every image of an array. The canvas grows by the margins and the original pixels are kept as they are.
6
21
 
7
22
  **Real-World Applications:**
8
23
  - **Social Media Formatting**: Add borders for consistent post dimensions
@@ -16,65 +31,56 @@ The `padding` node adds margins around images with configurable colors and dimen
16
31
  ## Input/Output Specification
17
32
 
18
33
  ### Inputs
19
- - **Single Image**: Standard image object format
20
- - **Image Array**: Array of image objects for batch padding
21
- - **Dynamic Values**: Padding dimensions can be provided via message properties
34
+ - **Single Image**: a raw image object, or an encoded JPEG/PNG/WebP/BMP `Buffer` (decoded by the addon)
35
+ - **Image Array**: an array of images, padded in parallel with the same margins; the output is an array in the same order
36
+ - **Dynamic Values**: each margin can be read from `msg`, `flow` or `global`
22
37
 
23
38
  ### Outputs
24
- - **Padded Image**: Original image with added margins
25
- - **Expanded Dimensions**: Canvas size increased by padding amounts
26
- - **Format Options**: Raw image object or encoded file formats
39
+ One output, written to **Output** (`msg.payload` by default):
40
+ - **Padded Image**: a raw image object of `width + left + right` by `height + top + bottom` pixels, or an encoded `Buffer` (JPEG/PNG/WebP)
41
+ - `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds
27
42
 
28
43
  ## Configuration Options
29
44
 
30
- ### Input/Output Paths
31
- - **Input From**: `msg.payload` (default), `flow.*`, `global.*`
32
- - **Output To**: `msg.payload` (default), `flow.*`, `global.*`
45
+ | Property | Default | Meaning |
46
+ |----------|---------|---------|
47
+ | Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
48
+ | Input | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
49
+ | Output | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
50
+ | Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP, with Quality (`90`), PNG Optimize and the WebP options as in [resize](./resize.md#output-format-options) |
51
+ | Debug / Debug Width | off / `200` | **Show processed image** under the node in the editor (the first image of an array) |
52
+ | Top | `0` | Margin above the image, in pixels |
53
+ | Bottom | `0` | Margin below the image, in pixels |
54
+ | Left | `0` | Margin on the left, in pixels |
55
+ | Right | `0` | Margin on the right, in pixels |
56
+ | Colour | `#000000` | Colour of the margins |
57
+ | Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
33
58
 
34
59
  ### Padding Dimensions
60
+ - **Values**: whole pixels; decimals are truncated and an empty value means 0. Negative values are not supported (OpenCV rejects them and the node reports the error)
61
+ - **Sources**: Number, `msg.*`, `flow.*`, `global.*`. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
35
62
 
36
- #### Top Padding
37
- - **Type**: Pixels (integer)
38
- - **Sources**: Number, `msg.*`, `flow.*`, `global.*`
39
- - **Effect**: Adds space above the image
40
-
41
- #### Right Padding
42
- - **Type**: Pixels (integer)
43
- - **Sources**: Number, `msg.*`, `flow.*`, `global.*`
44
- - **Effect**: Adds space to the right of the image
63
+ ### Color Configuration
64
+ - **Colour**: picked with the editor's colour picker (`#RRGGBB`); default black
65
+ - **Images with alpha** (RGBA, BGRA): the margins are transparent; their colour channels hold the pad colour
45
66
 
46
- #### Bottom Padding
47
- - **Type**: Pixels (integer)
48
- - **Sources**: Number, `msg.*`, `flow.*`, `global.*`
49
- - **Effect**: Adds space below the image
67
+ ### Output Format Options
68
+ - **Raw**: Standard image object (fastest between image nodes)
69
+ - **JPEG**: Compressed; the alpha channel is dropped, so transparent margins show the pad colour
70
+ - **PNG**: Lossless, keeps the alpha channel
71
+ - **WebP**: Keeps the alpha channel
50
72
 
51
- #### Left Padding
52
- - **Type**: Pixels (integer)
53
- - **Sources**: Number, `msg.*`, `flow.*`, `global.*`
54
- - **Effect**: Adds space to the left of the image
73
+ ### Inference
74
+ With **Transform inference coordinates** checked, the normalized coordinates of the detections and segmentations read from **Inf. Input** are recomputed for the larger canvas (measured on the first input image) and written to **Inf. Output**. Bitmap masks are padded too.
55
75
 
56
- ### Color Configuration
76
+ ## Status and Errors
57
77
 
58
- #### Padding Color
59
- - **Formats Supported**:
60
- - RGB: `rgb(255,0,0)`, `rgb(255,255,255)`
61
- - **Default**: Black
62
-
63
- ### Output Format Options
64
- - **Raw**: Standard image object (fastest for processing chains)
65
- - **JPEG**: Compressed (note: transparency becomes white)
66
- - **PNG**: Lossless with full transparency support
67
- - **WebP**: Modern format with transparency support
78
+ - **Success**: green dot `OK: <n> img in <t> ms (conv <c> | task <k> ms)` (no `ms` after the conversion time); with Debug on it reads `(conv <c> ms | task <k> ms)` followed by the preview format
79
+ - **Failure**: `msg.error` is set, the input is written back to **Output**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent
68
80
 
69
81
  ## Performance Notes
70
82
 
71
- ### C++ Backend Processing
72
- - **Efficient Canvas Expansion**: Optimized memory allocation for padded dimensions
73
- - **Color Fill**: Fast uniform color filling using OpenCV
74
- - **Memory Management**: Minimal memory overhead for padding operations
75
- - **Batch Processing**: Array inputs processed in parallel
76
-
77
- ### Dimension Calculations
83
+ - The margins are added with `cv::copyMakeBorder` in the native addon, on the libuv thread pool; the images of an array are processed concurrently
78
84
  - **New Width**: Original width + left padding + right padding
79
85
  - **New Height**: Original height + top padding + bottom padding
80
86
 
@@ -113,21 +119,15 @@ Add subtle borders to scanned documents.
113
119
  ## Common Issues & Troubleshooting
114
120
 
115
121
  ### Transparency Issues
116
- - **Issue**: Transparent padding appears white in JPEG
117
- - **Solution**: Use PNG or WebP format for transparency support
118
- - **Workaround**: Match padding color to expected background
122
+ - **Issue**: Margins of an RGBA image are transparent instead of coloured
123
+ - **Cause**: For images with alpha the margins get alpha 0
124
+ - **Solution**: Convert the image to RGB first ([color-convert](./color-convert.md)), or save as JPEG, which drops the alpha channel
119
125
 
120
126
  ### Large File Sizes
121
127
  - **Issue**: Padding significantly increases file size
122
128
  - **Cause**: Expanded canvas dimensions
123
129
  - **Solution**: Use appropriate compression settings, consider if padding is necessary
124
130
 
125
- ### Color Matching Problems
126
- - **Issue**: Padding color doesn't match expected appearance
127
- - **Solution**: Use exact color specifications (RGB codes)
128
- - **Testing**: Use debug mode to verify color appearance
129
-
130
131
  ### Dynamic Dimension Errors
131
132
  - **Issue**: Invalid padding values from message properties
132
- - **Solution**: Validate that dynamic sources contain positive integers
133
- - **Safety**: Add bounds checking in upstream nodes
133
+ - **Solution**: Make sure the dynamic sources hold zero or positive numbers
@@ -1,8 +1,23 @@
1
+ ---
2
+ title: "Resize Node - Scale Images"
3
+ description: "Scale images in Node-RED to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty. Part of @rosepetal/node-red-contrib-image-tools."
4
+ head:
5
+ - - meta
6
+ - name: "keywords"
7
+ content: "node-red, resize, scale image, thumbnail, aspect ratio, opencv, rosepetal"
8
+ - - meta
9
+ - property: "og:title"
10
+ content: "Resize Node - @rosepetal/node-red-contrib-image-tools"
11
+ - - meta
12
+ - property: "og:description"
13
+ content: "Scale images in Node-RED to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty."
14
+ ---
15
+
1
16
  # Resize Node
2
17
 
3
18
  ## Purpose & Use Cases
4
19
 
5
- The `resize` node provides high-performance image scaling with flexible dimension control and automatic aspect ratio preservation. It supports both fixed dimensions and proportional scaling using optimized C++ backend processing.
20
+ The `resize` node scales an image, or every image of an array, to a size in pixels or by a factor, and keeps the aspect ratio when one dimension is left empty. The scaling runs in the native OpenCV addon with bilinear interpolation.
6
21
 
7
22
  **Real-World Applications:**
8
23
  - **Web Image Optimization**: Scale images for different device sizes and bandwidths
@@ -16,9 +31,9 @@ The `resize` node provides high-performance image scaling with flexible dimensio
16
31
  ## Input/Output Specification
17
32
 
18
33
  ### Inputs
19
- - **Single Image**: Standard image object format
20
- - **Image Array**: Array of image objects for batch processing
21
- - **Dynamic Dimensions**: Dimensions can be provided via message properties
34
+ - **Single Image**: a raw image object, or an encoded JPEG/PNG/WebP/BMP `Buffer` (decoded by the addon)
35
+ - **Image Array**: an array of images, resized in parallel; the output is an array in the same order
36
+ - **Dynamic Dimensions**: Width and Height can be read from `msg`, `flow` or `global`
22
37
 
23
38
  ### Input Image Format
24
39
  ```javascript
@@ -27,79 +42,90 @@ The `resize` node provides high-performance image scaling with flexible dimensio
27
42
  width: number, // Original width in pixels
28
43
  height: number, // Original height in pixels
29
44
  channels: number, // Channel count (1, 3, 4)
30
- colorSpace: string, // "GRAY", "RGB", "RGBA"
45
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR" or "BGRA"
31
46
  dtype: string // "uint8"
32
47
  }
33
48
  ```
34
49
 
35
50
  ### Outputs
36
- Output format depends on the Output Format setting:
37
- - **Raw**: Standard image object (fastest for processing chains)
38
- - **JPEG/PNG/WebP**: Encoded file buffer ready for storage/transmission
51
+ One output. The result is written to **Output to** and its form depends on **Output Format**:
52
+ - **Raw**: an image object with the new `width` and `height` and the same channels and color space
53
+ - **JPEG/PNG/WebP**: an encoded `Buffer`
54
+
55
+ The node also sets `msg.performance.rpimage.<key>` (`{ conversion, task, total }` in milliseconds) and, with **Inference** checked, writes the detections back (see below).
39
56
 
40
57
  ## Configuration Options
41
58
 
42
- ### Input/Output Paths
43
- - **Input From**: `msg.payload` (default), `flow.*`, `global.*`
44
- - **Output To**: `msg.payload` (default), `flow.*`, `global.*`
45
- - **Purpose**: Flexible data routing for complex workflows
59
+ | Property | Default | Meaning |
60
+ |----------|---------|---------|
61
+ | Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
62
+ | Input from | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
63
+ | Output to | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
64
+ | Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP |
65
+ | Quality | `90` | JPEG and WebP quality, 1-100 |
66
+ | PNG Optimize | off | **Compress PNG (slower, smaller file)**: PNG compression level 6 instead of 0 |
67
+ | Lossless / Smart Subsample / Effort | off / off / empty | WebP options. When any of them is set, the WebP is encoded with `sharp` (Effort 0-6) instead of OpenCV |
68
+ | Debug | off | **Show processed image**: a preview under the node in the editor (the first image of an array) |
69
+ | Debug Width | `200` | Width of the preview in pixels: a number, or read from `msg`, `flow` or `global` |
70
+ | Width | Set to, empty | Mode (**Set to** or **Multiply by**) and value: a number, or read from `msg`, `flow` or `global` |
71
+ | Height | Set to, empty | Same as Width |
72
+ | Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
46
73
 
47
74
  ### Dimension Configuration
48
75
 
49
76
  #### Width Settings
50
77
  - **Mode**:
51
- - **Set to**: Fixed pixel value (e.g., 800 pixels)
52
- - **Multiply by**: Scale factor (e.g., 0.5 for half size)
53
- - **Value Sources**:
54
- - **Number**: Fixed value
55
- - **msg.***: Dynamic from message property
56
- - **flow.***: From flow context
57
- - **global.***: From global context
58
- - **Auto Mode**: Leave empty for automatic aspect ratio preservation
78
+ - **Set to**: the width in pixels (e.g., 800)
79
+ - **Multiply by**: a factor of the input width (e.g., 0.5 for half size)
80
+ - **Value Sources**: a number, or a `msg`, `flow` or `global` property. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
81
+ - **Auto**: leave it empty (or 0) and the width follows from the height, keeping the aspect ratio
59
82
 
60
83
  #### Height Settings
61
84
  - **Mode**: Same options as width (Set to / Multiply by)
62
- - **Value Sources**: Same dynamic options as width
63
- - **Auto Mode**: Leave empty for proportional scaling
85
+ - **Value Sources**: Same as width
86
+ - **Auto**: leave it empty (or 0) and the height follows from the width
87
+
88
+ Results are rounded to whole pixels. Leaving both empty fails with `Both dimensions are Auto`. An output larger than 4 GiB is refused; the limit can be changed with the environment variable `ROSEPETAL_MAX_RESIZE_BYTES` (in bytes) of the Node-RED process.
64
89
 
65
90
  ### Output Format Options
66
91
 
67
92
  #### Raw Format (Default)
68
- - **Performance**: Fastest option for processing chains
69
- - **Use Case**: When passing to other transform nodes
93
+ - **Performance**: no encoding; the fastest option between image nodes
94
+ - **Use Case**: When passing to other image nodes
70
95
 
71
96
  #### JPEG Format
72
97
  - **Quality**: 1-100 (default: 90)
73
- - **Use Case**: Final output, web optimization
74
- - **Compression**: Lossy, smaller file sizes
98
+ - **Use Case**: Final output, small files
99
+ - **Compression**: Lossy; the alpha channel is dropped
75
100
 
76
101
  #### PNG Format
77
- - **Optimize**: Checkbox for additional compression
78
- - **Use Case**: When transparency needed or lossless required
102
+ - **PNG Optimize**: compression level 6 when checked, 0 (fastest, largest) otherwise
103
+ - **Use Case**: When transparency or lossless output is needed
79
104
  - **Compression**: Lossless
80
105
 
81
106
  #### WebP Format
82
107
  - **Quality**: 1-100 (default: 90)
83
- - **Use Case**: Modern web applications
84
- - **Compression**: Superior to JPEG at same quality
108
+ - **Lossless**, **Smart Subsample** (lossy only) and **Effort** (0-6): encoded with `sharp` when any of them is set
109
+ - **Use Case**: Small files with alpha, lossy or lossless
85
110
 
86
111
  ### Debug Options
87
- - **Show Processed Image**: Visual preview in Node-RED editor
88
- - **Debug Width**: Preview image width in pixels
89
- - **Interactive**: Click preview to hide
112
+ - **Show processed image**: a preview of the result (or of the first image of an array) under the node in the editor, as JPEG for Raw output and in the output format otherwise
113
+ - **Debug Width**: width of the preview in pixels
114
+ - **Interactive**: click the preview to hide it
90
115
 
91
- ## Performance Notes
116
+ ### Inference
117
+ With **Transform inference coordinates** checked, the node reads the inference results at **Inf. Input** and writes them to **Inf. Output** after the image is resized. Normalized coordinates do not change with a resize, so boxes and polygons are written back unchanged. Bitmap masks of segmentations are resized to the new image size, except when the output is encoded by OpenCV (JPEG, PNG, or WebP without the `sharp` options): the new size is then not read back and the masks are left as they are. Only a non-empty array is processed; a failure logs `Inference transform: ...` and leaves the message as it is.
92
118
 
93
- ### C++ Backend Optimization
94
- - **High-Speed Processing**: OpenCV-based scaling algorithms
95
- - **Memory Efficient**: Optimized memory management for large images
96
- - **Parallel Processing**: Array inputs processed concurrently
97
- - **Algorithm**: Uses high-quality interpolation for best results
119
+ ## Status and Errors
120
+
121
+ - **Success**: green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, followed by the preview format with Debug on (`| jpg default (first)` for an array)
122
+ - **Failure**: the node sets `msg.error` (`message`, `operation`, `hint`, `details`, `timestamp`, `nodeId`, `nodeName`, `nodeType`), writes the input back to **Output to**, logs a warning, shows a red ring `Error: <first 30 characters>` and still sends the message. Invalid input images give `Invalid image structure` or `Invalid image list structure` with `msg.error.validationError` set to `true`
123
+
124
+ ## Performance Notes
98
125
 
99
- ### Processing Modes
100
- - **Batch Processing**: Arrays processed in parallel for maximum throughput
101
- - **Async Operations**: Non-blocking processing with timing display
102
- - **Status Display**: Real-time processing time and result information
126
+ - Resizing and encoding run in the native addon on the libuv thread pool, not on the Node-RED event loop
127
+ - The images of an array are resized concurrently
128
+ - Interpolation: bilinear (`cv::INTER_LINEAR`)
103
129
 
104
130
  ## Real-World Examples
105
131
 
@@ -111,17 +137,17 @@ Create web-optimized versions of high-resolution images.
111
137
 
112
138
  ### Responsive Image Set
113
139
  ```
114
- [Image-In] → [Resize: 1200x Auto] → [JPEG Quality 80] → [Large]
115
- → [Resize: 800x Auto] → [JPEG Quality 85] → [Medium]
116
- → [Resize: 400x Auto] → [JPEG Quality 90] → [Small]
140
+ [Image-In] → [Resize: 1200 x Auto, JPEG Quality 80] → [Large]
141
+ → [Resize: 800 x Auto, JPEG Quality 85] → [Medium]
142
+ → [Resize: 400 x Auto, JPEG Quality 90] → [Small]
117
143
  ```
118
144
  Generate multiple sizes for responsive web design.
119
145
 
120
146
  ### Thumbnail Generation
121
147
  ```
122
- [Image Array] → [Resize: 150x150] → [PNG] → [Thumbnail Gallery]
148
+ [Image Array] → [Resize: 150x150, PNG] → [Thumbnail Gallery]
123
149
  ```
124
- Create square thumbnails from image collections.
150
+ Create square thumbnails from image collections (images that are not square are stretched).
125
151
 
126
152
  ### Batch Photo Processing
127
153
  ```
@@ -142,17 +168,16 @@ Resize based on runtime requirements.
142
168
  - **Cause**: Both width and height set without considering aspect ratio
143
169
  - **Solution**: Leave one dimension empty for auto-calculation
144
170
 
145
- ### Memory Issues with Large Images
146
- - **Issue**: Processing very large images causes performance problems
147
- - **Solution**: Process in batches or reduce dimensions incrementally
148
- - **Best Practice**: Consider source image size vs. target size
171
+ ### Too Much Memory
172
+ - **Issue**: `Resize to WxH would allocate too much memory`
173
+ - **Cause**: The computed size is over 4 GiB, usually a pixel size typed in **Multiply by** mode or a wrong dynamic value
174
+ - **Solution**: Check the mode and the values; raise `ROSEPETAL_MAX_RESIZE_BYTES` only if such a size is intended
149
175
 
150
176
  ### Quality vs. File Size Balance
151
177
  - **Issue**: Output files too large or quality too low
152
- - **Solution**: Adjust quality settings (80-95 for good balance)
153
- - **Format Choice**: Use WebP for best compression, PNG for transparency
178
+ - **Solution**: Adjust the quality (80-95 is a common range), or check PNG Optimize for smaller PNG files
154
179
 
155
180
  ### Dynamic Value Errors
156
- - **Issue**: Runtime errors when using message properties
157
- - **Solution**: Validate dynamic values exist and are valid numbers
181
+ - **Issue**: `Value "..." from property "..." is not a valid number.` in `msg.error`
182
+ - **Solution**: Make sure the `msg`, `flow` or `global` property exists and holds a number
158
183
  - **Debugging**: Use debug nodes to verify property values
@@ -1,8 +1,23 @@
1
+ ---
2
+ title: "Rotate Node - Rotate Images by Any Angle"
3
+ description: "Rotate images in Node-RED by an angle in degrees and fill the uncovered area with a pad color. Part of @rosepetal/node-red-contrib-image-tools."
4
+ head:
5
+ - - meta
6
+ - name: "keywords"
7
+ content: "node-red, rotate, image rotation, angle, pad color, opencv, rosepetal"
8
+ - - meta
9
+ - property: "og:title"
10
+ content: "Rotate Node - @rosepetal/node-red-contrib-image-tools"
11
+ - - meta
12
+ - property: "og:description"
13
+ content: "Rotate images in Node-RED by an angle in degrees and fill the uncovered area with a pad color."
14
+ ---
15
+
1
16
  # Rotate Node
2
17
 
3
18
  ## Purpose & Use Cases
4
19
 
5
- The `rotate` node provides precise image rotation with customizable padding and background colors. It supports both clockwise and counter-clockwise rotation with automatic canvas adjustment to prevent clipping.
20
+ The `rotate` node rotates an image, or every image of an array, by any angle in degrees. The canvas grows so that the whole rotated image fits, and the uncovered corners are filled with a pad colour.
6
21
 
7
22
  **Real-World Applications:**
8
23
  - **Photo Orientation**: Correct camera orientation issues
@@ -16,54 +31,62 @@ The `rotate` node provides precise image rotation with customizable padding and
16
31
  ## Input/Output Specification
17
32
 
18
33
  ### Inputs
19
- - **Single Image**: Standard image object format
20
- - **Image Array**: Array of image objects for batch rotation
21
- - **Dynamic Angles**: Rotation angle can be provided via message properties
34
+ - **Single Image**: a raw image object, or an encoded JPEG/PNG/WebP/BMP `Buffer` (decoded by the addon)
35
+ - **Image Array**: an array of images, rotated in parallel by the same angle; the output is an array in the same order
36
+ - **Dynamic Angles**: the angle can be read from `msg`, `flow` or `global`
22
37
 
23
38
  ### Outputs
24
- - **Rotated Image**: Image rotated by specified angle with expanded canvas
25
- - **Format Options**: Raw image object or encoded file formats
39
+ One output, written to **Output** (`msg.payload` by default):
40
+ - **Rotated Image**: a raw image object with the size of the rotated image's bounding box, or an encoded `Buffer` (JPEG, PNG, WebP)
41
+ - `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds
26
42
 
27
43
  ## Configuration Options
28
44
 
29
- ### Input/Output Paths
30
- - **Input From**: `msg.payload` (default), `flow.*`, `global.*`
31
- - **Output To**: `msg.payload` (default), `flow.*`, `global.*`
45
+ | Property | Default | Meaning |
46
+ |----------|---------|---------|
47
+ | Name | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
48
+ | Input | `msg.payload` | Where the image or array is read (`msg`, `flow` or `global`) |
49
+ | Output | `msg.payload` | Where the result is written (`msg`, `flow` or `global`) |
50
+ | Output Format | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP |
51
+ | Quality | `90` | JPEG and WebP quality, 1-100 |
52
+ | PNG Optimize | off | PNG compression level 6 instead of 0 |
53
+ | Lossless / Smart Subsample / Effort | off / off / empty | WebP options; when any is set the WebP is encoded with `sharp` |
54
+ | Debug | off | **Show processed image** under the node in the editor (the first image of an array) |
55
+ | Debug Width | `200` | Width of the preview in pixels |
56
+ | Angle (°) | `90` | Rotation angle in degrees: a number, or read from `msg`, `flow` or `global`. Empty means 0 |
57
+ | Pad colour | `#000000` | Colour of the corners uncovered by the rotation |
58
+ | Inference | off | Under **Advanced options**: **Transform inference coordinates**, with **Inf. Input** and **Inf. Output** (both `msg.inference`) |
32
59
 
33
60
  ### Rotation Settings
34
61
 
35
62
  #### Angle
36
- - **Range**: 0-360 degrees (or negative for counter-clockwise)
37
- - **Precision**: Floating-point precision (e.g., 15.5 degrees)
38
- - **Sources**: Number, `msg.*`, `flow.*`, `global.*`
39
- - **Direction**: Positive = clockwise, Negative = counter-clockwise
63
+ - **Values**: any number of degrees, with decimals (e.g., 15.5); values beyond 360 or below 0 wrap around
64
+ - **Sources**: Number, `msg.*`, `flow.*`, `global.*`. A value that is not a number fails with `Value "..." from property "..." is not a valid number.`
65
+ - **Direction**: Positive = counter-clockwise, Negative = clockwise
66
+ - **Right angles**: 0, 90, 180 and 270 degrees are exact rotations without interpolation; other angles use bilinear interpolation
40
67
 
41
68
  #### Padding Settings
42
- - **Background Color**: Color to fill expanded canvas areas
43
- - **Color Formats**:
44
- - Hex: `#FF0000` (red)
45
- - RGB: `rgb(255,0,0)`
46
- - Named: `red`, `white`, `black`, `transparent`
47
- - **Default**: Black background
69
+ - **Pad colour**: picked with the editor's colour picker (`#RRGGBB`)
70
+ - **Images with alpha** (RGBA, BGRA): the padding is transparent, whatever the colour
48
71
 
49
72
  ### Output Format Options
50
- - **Raw**: Standard image object (fastest for processing chains)
51
- - **JPEG**: Compressed with quality control (1-100)
52
- - **PNG**: Lossless with transparency support
53
- - **WebP**: Modern format with quality control
73
+ - **Raw**: Standard image object (fastest between image nodes)
74
+ - **JPEG**: Compressed with quality control (1-100); the alpha channel is dropped
75
+ - **PNG**: Lossless, keeps the alpha channel
76
+ - **WebP**: Quality control (1-100), keeps the alpha channel
54
77
 
55
- ## Performance Notes
78
+ ### Inference
79
+ With **Transform inference coordinates** checked, the detections and segmentations read from **Inf. Input** get the same rotation, measured on the first input image, and are written to **Inf. Output**, so that their normalized coordinates match the rotated image. Bitmap masks are rotated too. Only a non-empty array is processed; a failure logs `Inference transform: ...`.
80
+
81
+ ## Status and Errors
56
82
 
57
- ### C++ Backend Processing
58
- - **High-Quality Rotation**: Uses OpenCV's optimized rotation algorithms
59
- - **Canvas Expansion**: Automatic canvas sizing to prevent clipping
60
- - **Memory Management**: Efficient handling of rotated image dimensions
61
- - **Interpolation**: High-quality pixel interpolation for smooth results
83
+ - **Success**: green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, plus the preview format with Debug on
84
+ - **Failure**: `msg.error` is set, the input is written back to **Output**, a warning is logged, the status shows a red ring `Error: <first 30 characters>` and the message is still sent. Invalid input images give `Invalid image structure` or `Invalid image list structure`
62
85
 
63
- ### Processing Characteristics
64
- - **Canvas Growth**: Output image may be larger than input to accommodate rotation
65
- - **Edge Handling**: Configurable background fill for exposed areas
66
- - **Precision**: Sub-pixel accuracy for precise angle control
86
+ ## Performance Notes
87
+
88
+ - Rotation and encoding run in the native OpenCV addon on the libuv thread pool
89
+ - **Canvas Growth**: for angles that are not multiples of 90 the output is larger than the input; at 45 degrees a square image grows by a factor of about 1.41 on each side
67
90
 
68
91
  ## Real-World Examples
69
92
 
@@ -83,13 +106,13 @@ Correct slight rotation in scanned documents.
83
106
  ```
84
107
  [Photo Array] → [Rotate: msg.orientation] → [Corrected Photos]
85
108
  ```
86
- Apply different rotation angles based on EXIF data.
109
+ Apply one angle, read from the message, to every photo of the array.
87
110
 
88
111
  ### Artistic Composition
89
112
  ```
90
- [Logo Image] → [Rotate: 45°, Transparent background] → [Diamond Logo]
113
+ [Logo Image (RGBA)] → [Rotate: 45°, PNG] → [Diamond Logo]
91
114
  ```
92
- Create artistic rotated elements with transparency.
115
+ An RGBA logo rotated by 45 degrees gets transparent corners.
93
116
 
94
117
  ### Dynamic Rotation
95
118
  ```
@@ -103,19 +126,13 @@ Rotate based on image analysis results.
103
126
  - **Issue**: Output image larger than input
104
127
  - **Cause**: Canvas expansion to accommodate rotated content
105
128
  - **Expected**: Normal behavior to prevent clipping
106
- - **Solution**: Consider downstream processing for size constraints
129
+ - **Solution**: Follow with a [crop](./crop.md) or [resize](./resize.md) node if a fixed size is needed
107
130
 
108
131
  ### Background Color Issues
109
- - **Issue**: Unexpected background colors in rotated areas
110
- - **Solution**: Specify appropriate background color for your use case
111
- - **Transparency**: Use PNG format with transparent background for overlays
112
-
113
- ### Performance with Large Angles
114
- - **Issue**: Significant rotation (close to 45°, 135°, etc.) creates much larger images
115
- - **Optimization**: Consider if rotation is necessary or can be minimized
116
- - **Memory**: Monitor memory usage with very large images
117
-
118
- ### Precision vs. Speed
119
- - **Issue**: High-precision angles may be slower
120
- - **Balance**: Use appropriate precision for your requirements
121
- - **Optimization**: Round to nearest degree if precision not critical
132
+ - **Issue**: The corners are black, or transparent instead of the pad colour
133
+ - **Solution**: Set **Pad colour**; for images with alpha the corners are always transparent, so convert to RGB first if a coloured background is needed
134
+ - **Transparency**: Use PNG or WebP output to keep it; JPEG drops the alpha channel
135
+
136
+ ### Wrong Direction
137
+ - **Issue**: The image turns the opposite way
138
+ - **Solution**: Positive angles turn counter-clockwise; use a negative angle to turn clockwise