@rosepetal/node-red-contrib-image-tools 1.2.2 → 1.3.0

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 (43) hide show
  1. package/.github/workflows/build-prebuild.yml +3 -0
  2. package/install.sh +8 -0
  3. package/node-red-contrib-image-tools/lib/node-utils.js +64 -0
  4. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +242 -3
  5. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +10 -3
  6. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +282 -4
  7. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +15 -8
  8. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +206 -3
  9. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +10 -3
  10. package/node-red-contrib-image-tools/nodes/blend/blend.html +332 -4
  11. package/node-red-contrib-image-tools/nodes/blend/blend.js +10 -3
  12. package/node-red-contrib-image-tools/nodes/io/folder-in.html +147 -3
  13. package/node-red-contrib-image-tools/nodes/io/folder-in.js +2 -1
  14. package/node-red-contrib-image-tools/nodes/io/image-in.html +81 -2
  15. package/node-red-contrib-image-tools/nodes/io/image-in.js +2 -1
  16. package/node-red-contrib-image-tools/nodes/io/image-out.html +197 -3
  17. package/node-red-contrib-image-tools/nodes/io/image-out.js +2 -1
  18. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +398 -3
  19. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +11 -4
  20. package/node-red-contrib-image-tools/nodes/mix/concat.html +245 -5
  21. package/node-red-contrib-image-tools/nodes/mix/concat.js +10 -3
  22. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +307 -3
  23. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +10 -3
  24. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +217 -4
  25. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +11 -2
  26. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +285 -4
  27. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +9 -2
  28. package/node-red-contrib-image-tools/nodes/transform/color-convert.html +169 -6
  29. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +11 -2
  30. package/node-red-contrib-image-tools/nodes/transform/crop.html +237 -5
  31. package/node-red-contrib-image-tools/nodes/transform/crop.js +11 -2
  32. package/node-red-contrib-image-tools/nodes/transform/draw.html +152 -3
  33. package/node-red-contrib-image-tools/nodes/transform/draw.js +10 -3
  34. package/node-red-contrib-image-tools/nodes/transform/filter.html +369 -4
  35. package/node-red-contrib-image-tools/nodes/transform/filter.js +11 -2
  36. package/node-red-contrib-image-tools/nodes/transform/padding.html +316 -5
  37. package/node-red-contrib-image-tools/nodes/transform/padding.js +11 -2
  38. package/node-red-contrib-image-tools/nodes/transform/resize.html +203 -5
  39. package/node-red-contrib-image-tools/nodes/transform/resize.js +11 -2
  40. package/node-red-contrib-image-tools/nodes/transform/rotate.html +164 -5
  41. package/node-red-contrib-image-tools/nodes/transform/rotate.js +11 -2
  42. package/package.json +71 -71
  43. package/scripts/dual-register.js +267 -0
@@ -63,6 +63,8 @@ module.exports = function (RED) {
63
63
  const outputFormat = config.outputFormat || 'raw';
64
64
  const outputQuality = parseInt(config.outputQuality) || 90;
65
65
  const pngOptimize = config.pngOptimize || false;
66
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
67
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
66
68
  const preset = config.preset || 'ultra-fast';
67
69
  const returnMatrix = config.returnMatrix || false;
68
70
  const transformPolygon = config.transformPolygon || false;
@@ -250,13 +252,17 @@ module.exports = function (RED) {
250
252
  scale,
251
253
  maxIterations,
252
254
  terminationEps,
253
- outputFormat,
255
+ cppFormat,
254
256
  outputQuality,
255
257
  pngOptimize,
256
258
  returnMatrix,
257
259
  polygon
258
260
  );
259
261
 
262
+ if (useSharpWebp) {
263
+ result.image = await NodeUtils.encodeWebpAdvanced(result.image, config);
264
+ }
265
+
260
266
  /* ▸ Status: standardized success formatting ----------------------- */
261
267
  const total = performance.now() - startTime;
262
268
 
@@ -349,5 +355,6 @@ module.exports = function (RED) {
349
355
  });
350
356
  }
351
357
 
352
- RED.nodes.registerType('image-align', ImageAlignNode);
358
+ RED.nodes.registerType('rp-image-align', ImageAlignNode);
359
+ RED.nodes.registerType('image-align', ImageAlignNode); // legacy compat
353
360
  };
@@ -1,5 +1,5 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('color-convert', {
2
+ var _rpNodeCfg = {
3
3
  category : 'RP Image',
4
4
  color : '#DDA0DD',
5
5
  defaults : {
@@ -11,6 +11,9 @@
11
11
  outputFormat : { value:"raw" },
12
12
  outputQuality : { value:90 },
13
13
  pngOptimize : { value:false },
14
+ webpLossless : { value:false },
15
+ webpSmartSubsample : { value:false },
16
+ webpEffort : { value:"" },
14
17
  // Debug configuration
15
18
  debugEnabled : { value:false },
16
19
  debugWidth : { value:200 },
@@ -18,8 +21,8 @@
18
21
  targetColorSpace: { value:"RGB" }
19
22
  },
20
23
  inputs :1, outputs:1,
21
- icon:"font-awesome/fa-paint-brush",
22
- label:function(){ return this.name || "color-convert"; },
24
+ icon:"font-awesome/fa-eyedropper",
25
+ label:function(){ return this.name || "rp-color-convert"; },
23
26
 
24
27
  oneditprepare:function(){
25
28
  $("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
@@ -29,6 +32,12 @@
29
32
  const format = $("#node-input-outputFormat").val();
30
33
  $("#quality-row").toggle(format === "jpg" || format === "webp");
31
34
  $("#png-optimize-row").toggle(format === "png");
35
+
36
+ // Show WebP advanced options only when WebP is selected
37
+ const isWebp = format === "webp";
38
+ $("#webp-lossless-row").toggle(isWebp);
39
+ $("#webp-smartsubsample-row").toggle(isWebp);
40
+ $("#webp-effort-row").toggle(isWebp);
32
41
  }
33
42
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
34
43
  updateQualityVisibility(); // initial state
@@ -63,10 +72,78 @@
63
72
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
64
73
  });
65
74
  }
66
- });
75
+ };
76
+ RED.nodes.registerType('rp-color-convert', _rpNodeCfg);
77
+ RED.nodes.registerType('color-convert', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));
78
+ </script>
79
+
80
+ <script type="text/x-red" data-template-name="rp-color-convert">
81
+ <div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
82
+ <hr>
83
+ <div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
84
+ <div class="form-row"><label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label><input type="text" id="node-input-outputPath" style="width:70%;"><input type="hidden" id="node-input-outputPathType"></div>
85
+ <div class="form-row">
86
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
87
+ <select id="node-input-outputFormat" style="width: 200px;">
88
+ <option value="raw">Raw (fastest)</option>
89
+ <option value="jpg">JPEG</option>
90
+ <option value="png">PNG</option>
91
+ <option value="webp">WebP</option>
92
+ </select>
93
+ </div>
94
+ <div class="form-row" id="quality-row">
95
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
96
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
97
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
98
+ </div>
99
+ <div class="form-row" id="png-optimize-row" style="display: none;">
100
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
101
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
102
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
103
+ </div>
104
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
105
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
106
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
107
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
108
+ </div>
109
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
110
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
111
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
112
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
113
+ </div>
114
+ <div class="form-row" id="webp-effort-row" style="display: none;">
115
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
116
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
117
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
118
+ </div>
119
+
120
+ <!-- Debug Configuration -->
121
+ <div class="form-row">
122
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
123
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
124
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
125
+ </div>
126
+ <div class="form-row" id="debug-width-row" style="display: none;">
127
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
128
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
129
+ <input type="hidden" id="node-input-debugWidthType">
130
+ <span style="margin-left: 10px; color: #666;">pixels</span>
131
+ </div>
132
+
133
+ <hr>
134
+ <div class="form-row">
135
+ <label for="node-input-targetColorSpace"><i class="fa fa-paint-brush"></i> Target Color Space</label>
136
+ <select id="node-input-targetColorSpace" style="width: 200px;">
137
+ <option value="GRAY">Grayscale (GRAY)</option>
138
+ <option value="RGB">RGB</option>
139
+ <option value="RGBA">RGBA</option>
140
+ <option value="BGR">BGR</option>
141
+ <option value="BGRA">BGRA</option>
142
+ </select>
143
+ </div>
67
144
  </script>
68
145
 
69
- <script type="text/x-red" data-template-name="color-convert">
146
+ <script type="text/x-red" data-template-name="color-convert">
70
147
  <div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
71
148
  <hr>
72
149
  <div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
@@ -90,6 +167,21 @@
90
167
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
91
168
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
92
169
  </div>
170
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
171
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
172
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
173
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
174
+ </div>
175
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
176
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
177
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
178
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
179
+ </div>
180
+ <div class="form-row" id="webp-effort-row" style="display: none;">
181
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
182
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
183
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
184
+ </div>
93
185
 
94
186
  <!-- Debug Configuration -->
95
187
  <div class="form-row">
@@ -117,7 +209,78 @@
117
209
  </div>
118
210
  </script>
119
211
 
120
- <script type="text/x-red" data-help-name="color-convert">
212
+ <script type="text/x-red" data-help-name="rp-color-convert">
213
+ <p>Converts images between color spaces (GRAY, RGB, RGBA, BGR, BGRA) using high-performance C++ processing.</p>
214
+
215
+ <h3>Details</h3>
216
+ <p>This node converts images from one color space to another. The source color space is automatically detected from the input image metadata (or inferred from channel count). The target color space is selected in the node configuration. Supports both single images and arrays, processed in parallel.</p>
217
+
218
+ <h3>Properties</h3>
219
+ <dl class="message-properties">
220
+ <dt>Input from <span class="property-type">string</span></dt>
221
+ <dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
222
+ <dt>Output to <span class="property-type">string</span></dt>
223
+ <dd>The location where the converted image will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
224
+ <dt>Output Format <span class="property-type">string</span></dt>
225
+ <dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
226
+ <dt>Quality <span class="property-type">number</span></dt>
227
+ <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
228
+ <dt>Target Color Space <span class="property-type">string</span></dt>
229
+ <dd>The target color space to convert images to. Options: <code>GRAY</code>, <code>RGB</code>, <code>RGBA</code>, <code>BGR</code>, <code>BGRA</code>. Default: RGB.</dd>
230
+ </dl>
231
+
232
+ <h3>Inputs</h3>
233
+ <dl class="message-properties">
234
+ <dt>payload <span class="property-type">object | array</span></dt>
235
+ <dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
236
+ </dl>
237
+
238
+ <h3>Outputs</h3>
239
+ <dl class="message-properties">
240
+ <dt>payload <span class="property-type">object | array | Buffer</span></dt>
241
+ <dd>Converted image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
242
+ </dl>
243
+
244
+ <h3>Supported Conversions</h3>
245
+ <p>All 20 conversion paths between the 5 color spaces are supported:</p>
246
+ <ul>
247
+ <li><strong>GRAY &rarr;</strong> BGR, RGB, BGRA, RGBA</li>
248
+ <li><strong>BGR &rarr;</strong> GRAY, RGB, BGRA, RGBA</li>
249
+ <li><strong>RGB &rarr;</strong> GRAY, BGR, BGRA, RGBA</li>
250
+ <li><strong>BGRA &rarr;</strong> GRAY, BGR, RGB, RGBA</li>
251
+ <li><strong>RGBA &rarr;</strong> GRAY, BGR, RGB, BGRA</li>
252
+ </ul>
253
+ <p>If the source and target color space are the same, a fast passthrough is used (no conversion overhead).</p>
254
+
255
+ <h3>Examples</h3>
256
+ <ul>
257
+ <li><strong>RGB &rarr; GRAY:</strong> Convert a color image to grayscale (3 channels &rarr; 1 channel)</li>
258
+ <li><strong>GRAY &rarr; RGBA:</strong> Expand grayscale to RGBA with full alpha (1 channel &rarr; 4 channels)</li>
259
+ <li><strong>BGR &rarr; RGB:</strong> Swap blue and red channels for display compatibility</li>
260
+ <li><strong>RGB &rarr; BGRA:</strong> Add alpha channel and convert to OpenCV-native order</li>
261
+ </ul>
262
+
263
+ <h3>Node Interactions</h3>
264
+ <p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
265
+ <p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
266
+ <p><strong>Common Workflows:</strong> Preparing images for specific processing pipelines, ensuring consistent color spaces before blending or concatenation</p>
267
+
268
+ <h3>Output Formats</h3>
269
+ <ul>
270
+ <li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
271
+ <li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
272
+ <li><strong>PNG:</strong> Lossless compressed file buffer</li>
273
+ <li><strong>WebP:</strong> Modern compressed format with quality setting</li>
274
+ </ul>
275
+
276
+ <h3>Error Handling</h3>
277
+ <p>The node validates input data and displays warnings for invalid inputs. Unsupported conversion paths produce descriptive error messages. Processing errors are logged and the original message is passed through with error details.</p>
278
+
279
+ <h3>Performance</h3>
280
+ <p>Uses optimized C++ backend with OpenCV for high-performance color space conversion. Identity conversions (same source/target) use a zero-cost passthrough. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
281
+ </script>
282
+
283
+ <script type="text/x-red" data-help-name="color-convert">
121
284
  <p>Converts images between color spaces (GRAY, RGB, RGBA, BGR, BGRA) using high-performance C++ processing.</p>
122
285
 
123
286
  <h3>Details</h3>
@@ -42,6 +42,8 @@ module.exports = function (RED) {
42
42
  const outputFormat = config.outputFormat || 'raw';
43
43
  const outputQuality = parseInt(config.outputQuality) || 90;
44
44
  const pngOptimize = config.pngOptimize || false;
45
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
46
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
45
47
  const targetColorSpace = config.targetColorSpace || 'RGB';
46
48
 
47
49
  // Validate input images with error passthrough
@@ -65,7 +67,7 @@ module.exports = function (RED) {
65
67
 
66
68
  /* ——— launch conversions in parallel ——— */
67
69
  const promises = imgs.map(img =>
68
- CppProcessor.colorConvert(img, targetColorSpace, outputFormat, outputQuality, pngOptimize)
70
+ CppProcessor.colorConvert(img, targetColorSpace, cppFormat, outputQuality, pngOptimize)
69
71
  );
70
72
 
71
73
  const results = await Promise.all(promises);
@@ -80,6 +82,12 @@ module.exports = function (RED) {
80
82
  return acc;
81
83
  }, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
82
84
 
85
+ if (useSharpWebp) {
86
+ for (let i = 0; i < images.length; i++) {
87
+ images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
88
+ }
89
+ }
90
+
83
91
  const out = Array.isArray(originalPayload) ? images : images[0];
84
92
  const durMs = performance.now() - t0;
85
93
 
@@ -149,5 +157,6 @@ module.exports = function (RED) {
149
157
  });
150
158
  }
151
159
 
152
- RED.nodes.registerType('color-convert', ColorConvertNode);
160
+ RED.nodes.registerType('rp-color-convert', ColorConvertNode);
161
+ RED.nodes.registerType('color-convert', ColorConvertNode); // legacy compat
153
162
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- 1 ▸ Runtime registration -->
4
4
  <script type="text/javascript">
5
- RED.nodes.registerType('crop',{
5
+ var _rpNodeCfg = {
6
6
 
7
7
  category:'RP Image',
8
8
  color :'#DDA0DD',
@@ -15,6 +15,9 @@
15
15
  outputFormat:{value:"raw"},
16
16
  outputQuality:{value:90},
17
17
  pngOptimize:{value:false},
18
+ webpLossless:{value:false},
19
+ webpSmartSubsample:{value:false},
20
+ webpEffort:{value:""},
18
21
  // Debug configuration
19
22
  debugEnabled:{value:false},
20
23
  debugWidth:{value:200},
@@ -30,7 +33,7 @@
30
33
  },
31
34
 
32
35
  inputs:1, outputs:1,
33
- label:function(){ return this.name || "crop"; },
36
+ label:function(){ return this.name || "rp-crop"; },
34
37
 
35
38
  /* ---------------- oneditprepare ---------------- */
36
39
  oneditprepare:function(){
@@ -68,6 +71,12 @@
68
71
  const format = $("#node-input-outputFormat").val();
69
72
  $("#quality-row").toggle(format === "jpg" || format === "webp");
70
73
  $("#png-optimize-row").toggle(format === "png");
74
+
75
+ // Show WebP advanced options only when WebP is selected
76
+ const isWebp = format === "webp";
77
+ $("#webp-lossless-row").toggle(isWebp);
78
+ $("#webp-smartsubsample-row").toggle(isWebp);
79
+ $("#webp-effort-row").toggle(isWebp);
71
80
  }
72
81
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
73
82
  updateQualityVisibility(); // initial state
@@ -103,7 +112,9 @@
103
112
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
104
113
  });
105
114
  }
106
- });
115
+ };
116
+ RED.nodes.registerType('rp-crop', _rpNodeCfg);
117
+ RED.nodes.registerType('crop', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));
107
118
 
108
119
  // Debug image display renderer - shared across all image processing nodes
109
120
  if (!window.debugImageRendererInitialized) {
@@ -216,7 +227,7 @@
216
227
  </script>
217
228
 
218
229
  <!-- 2 ▸ Edit‑dialog template -->
219
- <script type="text/x-red" data-template-name="crop">
230
+ <script type="text/x-red" data-template-name="rp-crop">
220
231
 
221
232
  <!-- Name -->
222
233
  <div class="form-row">
@@ -256,7 +267,138 @@
256
267
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
257
268
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
258
269
  </div>
270
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
271
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
272
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
273
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
274
+ </div>
275
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
276
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
277
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
278
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
279
+ </div>
280
+ <div class="form-row" id="webp-effort-row" style="display: none;">
281
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
282
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
283
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
284
+ </div>
285
+
286
+ <!-- Debug Configuration -->
287
+ <div class="form-row">
288
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
289
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
290
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
291
+ </div>
292
+ <div class="form-row" id="debug-width-row" style="display: none;">
293
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
294
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
295
+ <input type="hidden" id="node-input-debugWidthType">
296
+ <span style="margin-left: 10px; color: #666;">pixels</span>
297
+ </div>
298
+
299
+ <hr>
300
+
301
+ <!-- CROP-SPECIFIC SECTION -->
302
+ <div class="form-row">
303
+ <label for="node-input-coordNorm"><i class="fa fa-percent"></i> Normalised</label>
304
+ <input type="checkbox" id="node-input-coordNorm" style="width: 20px; height: 20px;">
305
+ </div>
306
+
307
+ <!-- Tips that toggle -->
308
+ <div id="norm-enabled" class="form-tips" style="font-size: 0.85em; margin: 4px 0; color: #666;">
309
+ <b>Normalised ON:</b> values must be between <code>0.0</code> and <code>1.0</code> (fractions of image dimensions).
310
+ </div>
311
+ <div id="norm-disabled" class="form-tips" style="font-size: 0.85em; margin: 4px 0; color: #666;">
312
+ <b>Normalised OFF:</b> values are absolute pixels from top-left corner.
313
+ </div>
314
+
315
+ <div class="form-row">
316
+ <label for="node-input-cropX"><i class="fa fa-arrows-h"></i> X Position</label>
317
+ <input type="text" id="node-input-cropX" style="width: 70%;" placeholder="0">
318
+ <input type="hidden" id="node-input-cropXType">
319
+ </div>
320
+ <div class="form-row">
321
+ <label for="node-input-cropY"><i class="fa fa-arrows-v"></i> Y Position</label>
322
+ <input type="text" id="node-input-cropY" style="width: 70%;" placeholder="0">
323
+ <input type="hidden" id="node-input-cropYType">
324
+ </div>
325
+ <div class="form-row">
326
+ <label for="node-input-width"><i class="fa fa-arrows-h"></i> Width</label>
327
+ <input type="text" id="node-input-width" style="width: 70%;" placeholder="100">
328
+ <input type="hidden" id="node-input-widthType">
329
+ </div>
330
+ <div class="form-row">
331
+ <label for="node-input-height"><i class="fa fa-arrows-v"></i> Height</label>
332
+ <input type="text" id="node-input-height" style="width: 70%;" placeholder="100">
333
+ <input type="hidden" id="node-input-heightType">
334
+ </div>
335
+
336
+ <div class="form-tips">
337
+ <b>Tips:</b>
338
+ <ul>
339
+ <li><b>X, Y:</b> Position of the top-left corner of the crop area.</li>
340
+ <li><b>Width, Height:</b> Dimensions of the crop area.</li>
341
+ <li>All parameters support dynamic values from <code>msg</code>, <code>flow</code>, or <code>global</code> context.</li>
342
+ </ul>
343
+ </div>
344
+ </script>
345
+
346
+ <script type="text/x-red" data-template-name="crop">
347
+
348
+ <!-- Name -->
349
+ <div class="form-row">
350
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
351
+ <input type="text" id="node-input-name" placeholder="Name">
352
+ </div>
259
353
 
354
+ <hr>
355
+
356
+ <!-- STANDARD I/O SECTION (same as all other nodes) -->
357
+ <div class="form-row">
358
+ <label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
359
+ <input type="text" id="node-input-inputPath" style="width: 70%;">
360
+ <input type="hidden" id="node-input-inputPathType">
361
+ </div>
362
+ <div class="form-row">
363
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
364
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
365
+ <input type="hidden" id="node-input-outputPathType">
366
+ </div>
367
+ <div class="form-row">
368
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
369
+ <select id="node-input-outputFormat" style="width: 200px;">
370
+ <option value="raw">Raw (fastest)</option>
371
+ <option value="jpg">JPEG</option>
372
+ <option value="png">PNG</option>
373
+ <option value="webp">WebP</option>
374
+ </select>
375
+ </div>
376
+ <div class="form-row" id="quality-row">
377
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
378
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
379
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
380
+ </div>
381
+ <div class="form-row" id="png-optimize-row" style="display: none;">
382
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
383
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
384
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
385
+ </div>
386
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
387
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
388
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
389
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
390
+ </div>
391
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
392
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
393
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
394
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
395
+ </div>
396
+ <div class="form-row" id="webp-effort-row" style="display: none;">
397
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
398
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
399
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
400
+ </div>
401
+
260
402
  <!-- Debug Configuration -->
261
403
  <div class="form-row">
262
404
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -318,7 +460,97 @@
318
460
  </script>
319
461
 
320
462
  <!-- 3 ▸ Help panel -->
321
- <script type="text/x-red" data-help-name="crop">
463
+ <script type="text/x-red" data-help-name="rp-crop">
464
+ <p>Extracts a rectangular region from images using flexible coordinate systems and dynamic value sources.</p>
465
+
466
+ <h3>Details</h3>
467
+ <p>This node crops images by extracting a rectangular region defined by X, Y position and width, height dimensions. It supports both normalized coordinates (0-1 relative to image dimensions) and absolute pixel coordinates. All coordinate values can be dynamically sourced from message properties, flow, or global context.</p>
468
+
469
+ <h3>Properties</h3>
470
+ <dl class="message-properties">
471
+ <dt>Input from <span class="property-type">string</span></dt>
472
+ <dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
473
+ <dt>Output to <span class="property-type">string</span></dt>
474
+ <dd>The location where the cropped image will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
475
+ <dt>Output Format <span class="property-type">string</span></dt>
476
+ <dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
477
+ <dt>Quality <span class="property-type">number</span></dt>
478
+ <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
479
+ <dt>Normalised <span class="property-type">boolean</span></dt>
480
+ <dd>When enabled, coordinates are normalized (0.0-1.0 as fractions of image dimensions). When disabled, coordinates are absolute pixels.</dd>
481
+ <dt>X Position <span class="property-type">number|string</span></dt>
482
+ <dd>X coordinate of the top-left corner of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
483
+ <dt>Y Position <span class="property-type">number|string</span></dt>
484
+ <dd>Y coordinate of the top-left corner of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
485
+ <dt>Width <span class="property-type">number|string</span></dt>
486
+ <dd>Width of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
487
+ <dt>Height <span class="property-type">number|string</span></dt>
488
+ <dd>Height of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
489
+ </dl>
490
+
491
+ <h3>Inputs</h3>
492
+ <dl class="message-properties">
493
+ <dt>payload <span class="property-type">object | array</span></dt>
494
+ <dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
495
+ </dl>
496
+
497
+ <h3>Outputs</h3>
498
+ <dl class="message-properties">
499
+ <dt>payload <span class="property-type">object | array | Buffer</span></dt>
500
+ <dd>Cropped image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
501
+ </dl>
502
+
503
+ <h3>Coordinate Systems</h3>
504
+ <p><strong>Normalized Coordinates (0.0-1.0):</strong></p>
505
+ <ul>
506
+ <li><strong>Advantages:</strong> Resolution-independent, easy to work with percentages</li>
507
+ <li><strong>Example:</strong> X=0.25, Y=0.25, Width=0.5, Height=0.5 crops the center quarter of any image</li>
508
+ <li><strong>Range:</strong> All values must be between 0.0 and 1.0</li>
509
+ </ul>
510
+ <p><strong>Absolute Pixel Coordinates:</strong></p>
511
+ <ul>
512
+ <li><strong>Advantages:</strong> Precise pixel-level control</li>
513
+ <li><strong>Example:</strong> X=100, Y=50, Width=200, Height=150 crops a 200x150 region starting at pixel (100,50)</li>
514
+ <li><strong>Range:</strong> Values are in pixels from top-left corner</li>
515
+ </ul>
516
+
517
+ <h3>Examples</h3>
518
+ <ul>
519
+ <li><strong>Center Crop (Normalized):</strong> X=0.25, Y=0.25, Width=0.5, Height=0.5 → Center quarter of image</li>
520
+ <li><strong>Top-Left Corner (Pixels):</strong> X=0, Y=0, Width=100, Height=100 → 100x100 pixel square from top-left</li>
521
+ <li><strong>Dynamic Crop:</strong> X=msg.cropX, Y=msg.cropY → Use coordinates from message properties</li>
522
+ <li><strong>Face Detection Crop:</strong> Coordinates calculated by face detection → dynamic cropping based on detected faces</li>
523
+ </ul>
524
+
525
+ <h3>Node Interactions</h3>
526
+ <p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
527
+ <p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
528
+ <p><strong>Common Workflows:</strong> Face detection → Crop, Image preprocessing → Crop → Resize, Batch cropping for thumbnails</p>
529
+
530
+ <h3>Output Formats</h3>
531
+ <ul>
532
+ <li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
533
+ <li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
534
+ <li><strong>PNG:</strong> Lossless compressed file buffer</li>
535
+ <li><strong>WebP:</strong> Modern compressed format with quality setting</li>
536
+ </ul>
537
+
538
+ <h3>Boundary Handling</h3>
539
+ <p>The node automatically handles boundary conditions:</p>
540
+ <ul>
541
+ <li><strong>Out-of-bounds:</strong> Crop area is clipped to image boundaries</li>
542
+ <li><strong>Invalid coordinates:</strong> Negative positions are clamped to 0</li>
543
+ <li><strong>Oversized dimensions:</strong> Width/height automatically limited to available space</li>
544
+ </ul>
545
+
546
+ <h3>Error Handling</h3>
547
+ <p>The node validates input data and coordinates, displaying warnings for invalid inputs. Invalid coordinates are clamped to valid ranges. Processing errors are logged and the message is not propagated.</p>
548
+
549
+ <h3>Performance</h3>
550
+ <p>Uses optimized C++ backend with OpenCV for high-performance cropping. Node status displays processing time including conversion, processing, and encoding phases. Array inputs are processed in parallel for optimal performance.</p>
551
+ </script>
552
+
553
+ <script type="text/x-red" data-help-name="crop">
322
554
  <p>Extracts a rectangular region from images using flexible coordinate systems and dynamic value sources.</p>
323
555
 
324
556
  <h3>Details</h3>
@@ -49,6 +49,8 @@ module.exports = function (RED) {
49
49
  const outputFormat = config.outputFormat || 'raw';
50
50
  const outputQuality = parseInt(config.outputQuality) || 90;
51
51
  const pngOptimize = config.pngOptimize || false;
52
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
53
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
52
54
 
53
55
  /* imagen o lista de imágenes */
54
56
  const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
@@ -77,7 +79,7 @@ module.exports = function (RED) {
77
79
 
78
80
  /* lanzar recortes en paralelo */
79
81
  const jobs = imgs.map(img =>
80
- CppProcessor.crop(img, x, y, width, height, normalized, outputFormat, outputQuality, pngOptimize)
82
+ CppProcessor.crop(img, x, y, width, height, normalized, cppFormat, outputQuality, pngOptimize)
81
83
  );
82
84
 
83
85
  const results = await Promise.all(jobs);
@@ -92,6 +94,12 @@ module.exports = function (RED) {
92
94
  return acc;
93
95
  }, { totalConvertMs: 0, totalTaskMs: 0, totalEncodeMs: 0, images: [] });
94
96
 
97
+ if (useSharpWebp) {
98
+ for (let i = 0; i < images.length; i++) {
99
+ images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
100
+ }
101
+ }
102
+
95
103
  /* salida */
96
104
  const out = Array.isArray(originalPayload) ? images : images[0];
97
105
  NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
@@ -166,5 +174,6 @@ module.exports = function (RED) {
166
174
  });
167
175
  }
168
176
 
169
- RED.nodes.registerType('crop', CropNode);
177
+ RED.nodes.registerType('rp-crop', CropNode);
178
+ RED.nodes.registerType('crop', CropNode); // legacy compat
170
179
  };