@rosepetal/node-red-contrib-image-tools 1.1.3

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 (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Node‑RED logic for *rosepetal‑padding* (C++ backend)
3
+ * Shows timings like the rest of the Rosepetal nodes.
4
+ */
5
+ const { performance } = require('perf_hooks');
6
+ const CppProcessor = require('../../lib/cpp-bridge.js');
7
+
8
+ module.exports = function (RED) {
9
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
10
+
11
+ function PaddingNode(cfg) {
12
+ RED.nodes.createNode(this, cfg);
13
+ const node = this;
14
+
15
+ node.on('input', async (msg, send, done) => {
16
+ /* paths */
17
+ const inPath = cfg.inputPath || 'payload';
18
+ const outPath = cfg.outputPath || 'payload';
19
+
20
+ /* image / array - capture original for error passthrough */
21
+ const originalPayload = RED.util.getMessageProperty(msg, inPath);
22
+
23
+ try {
24
+ const t0 = performance.now();
25
+ node.status({});
26
+
27
+ // Validate input images with error passthrough
28
+ if (Array.isArray(originalPayload)) {
29
+ if (!NodeUtils.validateListImage(originalPayload, node)) {
30
+ return NodeUtils.handleValidationErrorWithPassthrough(
31
+ node, 'Invalid image list structure', msg, send, done,
32
+ { originalPayload, outputPath: outPath, outputType: 'preserve' }
33
+ );
34
+ }
35
+ } else {
36
+ if (!NodeUtils.validateSingleImage(originalPayload, node)) {
37
+ return NodeUtils.handleValidationErrorWithPassthrough(
38
+ node, 'Invalid image structure', msg, send, done,
39
+ { originalPayload, outputPath: outPath, outputType: 'preserve' }
40
+ );
41
+ }
42
+ }
43
+
44
+ const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
45
+
46
+ /* static options from editor */
47
+ const outputFormat = cfg.outputFormat || 'raw';
48
+ const outputQuality = parseInt(cfg.outputQuality) || 90;
49
+ const pngOptimize = cfg.pngOptimize || false;
50
+ const padHex = cfg.padColor || '#000000';
51
+
52
+ /* numeric margins can come from msg / flow / global */
53
+ const tVal = Number(NodeUtils.resolveDimension(node, cfg.topType, cfg.top, msg));
54
+ const bVal = Number(NodeUtils.resolveDimension(node, cfg.bottomType, cfg.bottom, msg));
55
+ const lVal = Number(NodeUtils.resolveDimension(node, cfg.leftType, cfg.left, msg));
56
+ const rVal = Number(NodeUtils.resolveDimension(node, cfg.rightType, cfg.right, msg));
57
+
58
+ /* one C++ call per image (fast, runs in parallel) */
59
+ const tasks = imgs.map(img =>
60
+ CppProcessor.padding(img, tVal, bVal, lVal, rVal, padHex, outputFormat, outputQuality, pngOptimize)
61
+ );
62
+ const results = await Promise.all(tasks);
63
+
64
+ /* collect timings */
65
+ let cMs = 0, tMs = 0, eMs = 0;
66
+ const outImgs = results.map(r => {
67
+ cMs += r.timing.convertMs;
68
+ tMs += r.timing.taskMs;
69
+ eMs += r.timing.encodeMs;
70
+ return r.image;
71
+ });
72
+
73
+ RED.util.setMessageProperty(msg, outPath, Array.isArray(originalPayload) ? outImgs : outImgs[0]);
74
+
75
+ // Debug image display
76
+ const elapsedTime = performance.now() - t0;
77
+ let debugFormat = null;
78
+ if (cfg.debugEnabled) {
79
+ try {
80
+ // Resolve and validate debug width
81
+ let debugWidth = NodeUtils.resolveDimension(
82
+ node,
83
+ cfg.debugWidthType,
84
+ cfg.debugWidth,
85
+ msg
86
+ );
87
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
88
+
89
+ // For arrays, show the first image as representative
90
+ const debugImage = Array.isArray(originalPayload) ? outImgs[0] : outImgs[0];
91
+ const debugResult = await NodeUtils.debugImageDisplay(
92
+ debugImage,
93
+ outputFormat,
94
+ outputQuality,
95
+ node,
96
+ true,
97
+ debugWidth
98
+ );
99
+
100
+ if (debugResult) {
101
+ debugFormat = debugResult.formatMessage;
102
+ // Update node status with debug info
103
+ NodeUtils.setSuccessStatusWithDebug(node, imgs.length, elapsedTime, {
104
+ convertMs: cMs,
105
+ taskMs: tMs,
106
+ encodeMs: eMs
107
+ }, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
108
+ }
109
+ } catch (debugError) {
110
+ node.warn(`Debug display error: ${debugError.message}`);
111
+ }
112
+ }
113
+
114
+ // Set regular status if debug not enabled or failed
115
+ if (!debugFormat) {
116
+ /* node status */
117
+ node.status({
118
+ fill:'green', shape:'dot',
119
+ text:`OK: ${imgs.length} img in ${elapsedTime.toFixed(2)} ms `
120
+ + `(conv ${(cMs+eMs).toFixed(2)} | task ${tMs.toFixed(2)} ms)`
121
+ });
122
+
123
+ }
124
+
125
+ NodeUtils.recordPerformanceMetrics(node, msg, {
126
+ convertMs: cMs,
127
+ encodeMs: eMs,
128
+ taskMs: tMs
129
+ }, elapsedTime);
130
+
131
+ send(msg); done && done();
132
+ } catch (err) {
133
+ NodeUtils.handleNodeErrorWithPassthrough(
134
+ node, err, msg, send, done, 'padding processing',
135
+ { originalPayload, outputPath: outPath, outputType: 'preserve' }
136
+ );
137
+ }
138
+ });
139
+ }
140
+
141
+ RED.nodes.registerType('padding', PaddingNode);
142
+ };
@@ -0,0 +1,429 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('resize', {
3
+ category: 'RP Image',
4
+ color: '#DDA0DD',
5
+ defaults: {
6
+ name: { value: "" },
7
+ // Propiedades para la ruta de Entrada/Salida
8
+ inputPath: { value: "payload" },
9
+ inputPathType: { value: "msg" },
10
+ outputPath: { value: "payload" },
11
+ outputPathType: { value: "msg" },
12
+ outputFormat: { value: "raw" },
13
+ outputQuality: { value: 90 },
14
+ pngOptimize: { value: false },
15
+ // Debug configuration
16
+ debugEnabled: { value: false },
17
+ debugWidth: { value: 200 },
18
+ debugWidthType: { value: "num" },
19
+ // Propiedades para la configuración del Ancho (Width)
20
+ widthMode: { value: "set" },
21
+ widthValue: { value: "" },
22
+ widthType: { value: "num" }, // Tipo para el TypedInput
23
+ // Propiedades para la configuración del Alto (Height)
24
+ heightMode: { value: "set" },
25
+ heightValue: { value: "" },
26
+ heightType: { value: "num" } // Tipo para el TypedInput
27
+ },
28
+ inputs: 1,
29
+ outputs: 1,
30
+ icon: "font-awesome/fa-arrows-alt",
31
+ label: function() {
32
+ if (this.name) { return this.name; }
33
+ return `resize`;
34
+ },
35
+ oneditprepare: function() {
36
+ // === Inicialización de los Widgets "TypedInput" ===
37
+
38
+ // Para las rutas de Input y Output
39
+ $("#node-input-inputPath").typedInput({
40
+ default: 'msg',
41
+ types: ['msg', 'flow', 'global'],
42
+ typeField: "#node-input-inputPathType"
43
+ });
44
+ $("#node-input-outputPath").typedInput({
45
+ default: 'msg',
46
+ types: ['msg', 'flow', 'global'],
47
+ typeField: "#node-input-outputPathType"
48
+ });
49
+
50
+ // Para los valores de Width y Height, ahora con flow y global
51
+ const widthTypedInput = $("#node-input-widthValue").typedInput({
52
+ default: 'num',
53
+ types: ['num', 'msg', 'flow', 'global'], // Añadimos flow y global
54
+ typeField: "#node-input-widthType"
55
+ });
56
+ const heightTypedInput = $("#node-input-heightValue").typedInput({
57
+ default: 'num',
58
+ types: ['num', 'msg', 'flow', 'global'], // Añadimos flow y global
59
+ typeField: "#node-input-heightType"
60
+ });
61
+
62
+ // === Lógica de Placeholders "Auto" ===
63
+
64
+ function updatePlaceholders() {
65
+ const widthVal = widthTypedInput.typedInput('value');
66
+ const heightVal = heightTypedInput.typedInput('value');
67
+
68
+ // El widget TypedInput crea su propio campo de texto, lo seleccionamos
69
+ const widthInputField = widthTypedInput.parent().find('.red-ui-typedInput-input');
70
+ const heightInputField = heightTypedInput.parent().find('.red-ui-typedInput-input');
71
+
72
+ const originalWidthPlaceholder = "e.g., 800";
73
+ const originalHeightPlaceholder = "e.g., 600";
74
+
75
+ // Lógica final para los placeholders
76
+ if (widthVal === '' && heightVal === '') {
77
+ widthInputField.attr('placeholder', originalWidthPlaceholder);
78
+ heightInputField.attr('placeholder', originalHeightPlaceholder);
79
+ } else if (widthVal !== '' && heightVal === '') {
80
+ heightInputField.attr('placeholder', 'Auto');
81
+ widthInputField.attr('placeholder', originalWidthPlaceholder);
82
+ } else if (widthVal === '' && heightVal !== '') {
83
+ widthInputField.attr('placeholder', 'Auto');
84
+ heightInputField.attr('placeholder', originalHeightPlaceholder);
85
+ } else {
86
+ widthInputField.attr('placeholder', originalWidthPlaceholder);
87
+ heightInputField.attr('placeholder', originalHeightPlaceholder);
88
+ }
89
+ }
90
+
91
+ // Escuchamos el evento 'change' del widget, que se dispara cuando el tipo o el valor cambian
92
+ widthTypedInput.on('change', updatePlaceholders);
93
+ heightTypedInput.on('change', updatePlaceholders);
94
+
95
+ // Llamada inicial para configurar la UI
96
+ updatePlaceholders();
97
+
98
+ // === Output Format Logic ===
99
+ function updateQualityVisibility() {
100
+ const format = $('#node-input-outputFormat').val();
101
+ if (format === 'jpg' || format === 'webp') {
102
+ $('#quality-row').show();
103
+ } else {
104
+ $('#quality-row').hide();
105
+ }
106
+
107
+ // Show PNG optimize checkbox only when PNG is selected
108
+ if (format === 'png') {
109
+ $('#png-optimize-row').show();
110
+ } else {
111
+ $('#png-optimize-row').hide();
112
+ }
113
+ }
114
+
115
+ $('#node-input-outputFormat').on('change', updateQualityVisibility);
116
+ updateQualityVisibility(); // Initial call
117
+
118
+ // === Debug Display Logic ===
119
+ const debugCheckbox = $('#node-input-debugEnabled');
120
+ const debugWidthRow = $('#debug-width-row');
121
+
122
+ // Initialize debug width TypedInput
123
+ $("#node-input-debugWidth").typedInput({
124
+ default: 'num',
125
+ types: ['num', 'msg', 'flow', 'global'],
126
+ typeField: "#node-input-debugWidthType"
127
+ });
128
+
129
+ // Function to toggle debug width visibility
130
+ function updateDebugWidthVisibility() {
131
+ if (debugCheckbox.is(':checked')) {
132
+ debugWidthRow.show();
133
+ } else {
134
+ debugWidthRow.hide();
135
+ }
136
+ }
137
+
138
+ // Initialize debug state on node open
139
+ updateDebugWidthVisibility();
140
+
141
+ // Handle debug checkbox changes
142
+ debugCheckbox.on('change', function() {
143
+ const enabled = this.checked;
144
+ updateDebugWidthVisibility();
145
+ // Store debug state for runtime access
146
+ $('#node-input-debugEnabled').data('debug-enabled', enabled);
147
+ });
148
+ }
149
+ });
150
+
151
+ // Debug image display renderer - shared across all image processing nodes
152
+ if (!window.debugImageRendererInitialized) {
153
+ window.debugImageRendererInitialized = true;
154
+
155
+ (function() {
156
+ var isSubscribed = false;
157
+
158
+ function subscribeToDebugImages() {
159
+ if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
160
+ isSubscribed = true;
161
+
162
+ RED.comms.subscribe('debug-image', function(event, data) {
163
+ if (!data || !data.id) return;
164
+
165
+ try {
166
+ renderDebugImage(data);
167
+ } catch (err) {
168
+ console.warn('Debug image render error:', err);
169
+ }
170
+ });
171
+ }
172
+
173
+ function renderDebugImage(data) {
174
+ const nodeId = data.id;
175
+ const base64Data = data.data;
176
+ const format = data.format || 'unknown';
177
+ const mimeType = data.mimeType || 'jpeg';
178
+
179
+ if (!base64Data) {
180
+ removeDebugImage(nodeId);
181
+ return;
182
+ }
183
+
184
+ const nodeElement = document.getElementById(nodeId);
185
+ if (!nodeElement) return;
186
+
187
+ // Get debug dimensions with fallbacks
188
+ const debugWidth = data.debugWidth || 200;
189
+ const debugHeight = data.debugHeight || 200;
190
+
191
+ // Apply reasonable maximum limits (500px max width)
192
+ const maxDisplayWidth = Math.min(debugWidth, 500);
193
+ const displayHeight = debugHeight * (maxDisplayWidth / debugWidth);
194
+
195
+ let debugContainer = document.getElementById('debug-img-container-' + nodeId);
196
+
197
+ if (!debugContainer) {
198
+ // Create SVG foreignObject to embed HTML content in SVG
199
+ debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
200
+ debugContainer.id = 'debug-img-container-' + nodeId;
201
+ debugContainer.setAttribute('x', '0');
202
+ debugContainer.setAttribute('y', '45');
203
+ debugContainer.setAttribute('width', maxDisplayWidth.toString());
204
+ debugContainer.setAttribute('height', displayHeight.toString());
205
+ debugContainer.style.overflow = 'visible';
206
+
207
+ // Create simple image directly inside foreignObject
208
+ const img = document.createElement('img');
209
+ img.id = 'debug-img-' + nodeId;
210
+ img.style.width = '100%';
211
+ img.style.height = 'auto';
212
+ img.style.display = 'block';
213
+ img.style.cursor = 'pointer';
214
+ // Remove fixed size constraints
215
+ img.style.maxHeight = 'none';
216
+ img.style.maxWidth = 'none';
217
+
218
+ img.onclick = function() {
219
+ removeDebugImage(nodeId);
220
+ };
221
+
222
+ debugContainer.appendChild(img);
223
+ nodeElement.appendChild(debugContainer);
224
+ } else {
225
+ // Update existing container dimensions
226
+ debugContainer.setAttribute('width', maxDisplayWidth.toString());
227
+ debugContainer.setAttribute('height', displayHeight.toString());
228
+ }
229
+
230
+ const img = document.getElementById('debug-img-' + nodeId);
231
+
232
+ if (img) {
233
+ img.src = `data:image/${mimeType};base64,${base64Data}`;
234
+ img.title = 'Debug image (click to hide)';
235
+ }
236
+ }
237
+
238
+ function removeDebugImage(nodeId) {
239
+ const debugContainer = document.getElementById('debug-img-container-' + nodeId);
240
+ if (debugContainer) {
241
+ debugContainer.remove();
242
+ }
243
+ }
244
+
245
+ function initializeWhenReady() {
246
+ if (typeof RED !== 'undefined' && RED.comms) {
247
+ subscribeToDebugImages();
248
+
249
+ // Clean up orphaned debug images periodically
250
+ setInterval(function() {
251
+ const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
252
+ debugContainers.forEach(container => {
253
+ const nodeId = container.id.replace('debug-img-container-', '');
254
+ const nodeElement = document.getElementById(nodeId);
255
+ if (!nodeElement) {
256
+ container.remove();
257
+ }
258
+ });
259
+ }, 5000);
260
+ } else {
261
+ setTimeout(initializeWhenReady, 100);
262
+ }
263
+ }
264
+
265
+ if (document.readyState === 'loading') {
266
+ document.addEventListener('DOMContentLoaded', initializeWhenReady);
267
+ } else {
268
+ initializeWhenReady();
269
+ }
270
+ })();
271
+ }
272
+ </script>
273
+
274
+ <script type="text/x-red" data-template-name="resize">
275
+ <div class="form-row">
276
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
277
+ <input type="text" id="node-input-name" placeholder="Name">
278
+ </div>
279
+
280
+ <hr>
281
+
282
+ <div class="form-row">
283
+ <label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
284
+ <input type="text" id="node-input-inputPath" style="width: 70%;">
285
+ <input type="hidden" id="node-input-inputPathType">
286
+ </div>
287
+ <div class="form-row">
288
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
289
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
290
+ <input type="hidden" id="node-input-outputPathType">
291
+
292
+ </div>
293
+ <div class="form-row">
294
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
295
+ <select id="node-input-outputFormat" style="width: 200px;">
296
+ <option value="raw">Raw (fastest)</option>
297
+ <option value="jpg">JPEG</option>
298
+ <option value="png">PNG</option>
299
+ <option value="webp">WebP</option>
300
+ </select>
301
+ </div>
302
+ <div class="form-row" id="quality-row">
303
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
304
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
305
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
306
+ </div>
307
+ <div class="form-row" id="png-optimize-row" style="display: none;">
308
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
309
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
310
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
311
+ </div>
312
+
313
+ <!-- Debug Configuration -->
314
+ <div class="form-row">
315
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
316
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
317
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
318
+ </div>
319
+ <div class="form-row" id="debug-width-row" style="display: none;">
320
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
321
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
322
+ <input type="hidden" id="node-input-debugWidthType">
323
+ <span style="margin-left: 10px; color: #666;">pixels</span>
324
+ </div>
325
+
326
+ <hr>
327
+
328
+ <div class="form-row">
329
+ <label><i class="fa fa-arrows-h"></i> Width</label>
330
+ <div style="display: flex; align-items: center; width: 70%;">
331
+ <select id="node-input-widthMode" style="width: 120px; margin-right: 5px;">
332
+ <option value="set">Set to</option>
333
+ <option value="multiply">Multiply by</option>
334
+ </select>
335
+ <input type="text" id="node-input-widthValue" style="flex-grow: 1;">
336
+ <input type="hidden" id="node-input-widthType">
337
+ </div>
338
+ </div>
339
+ <div class="form-row">
340
+ <label><i class="fa fa-arrows-v"></i> Height</label>
341
+ <div style="display: flex; align-items: center; width: 70%;">
342
+ <select id="node-input-heightMode" style="width: 120px; margin-right: 5px;">
343
+ <option value="set">Set to</option>
344
+ <option value="multiply">Multiply by</option>
345
+ </select>
346
+ <input type="text" id="node-input-heightValue" style="flex-grow: 1;">
347
+ <input type="hidden" id="node-input-heightType">
348
+ </div>
349
+ </div>
350
+
351
+ <div class="form-tips">
352
+ <b>Tip:</b> If a dimension value is left empty, it will be set to 'Auto' to maintain the original aspect ratio.
353
+ </div>
354
+ </script>
355
+
356
+ <script type="text/x-red" data-help-name="resize">
357
+ <p>Resizes images to specified dimensions using high-performance C++ processing with OpenCV backend.</p>
358
+
359
+ <h3>Details</h3>
360
+ <p>This node provides flexible image resizing capabilities with multiple operation modes and dynamic value sources. It supports both single images and arrays, with automatic aspect ratio preservation when one dimension is omitted. All processing is performed asynchronously using the optimized C++ backend.</p>
361
+
362
+ <h3>Properties</h3>
363
+ <dl class="message-properties">
364
+ <dt>Input from <span class="property-type">string</span></dt>
365
+ <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>
366
+ <dt>Output to <span class="property-type">string</span></dt>
367
+ <dd>The location where the resized 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>
368
+ <dt>Output Format <span class="property-type">string</span></dt>
369
+ <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>
370
+ <dt>Quality <span class="property-type">number</span></dt>
371
+ <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
372
+ <dt>Width Mode <span class="property-type">string</span></dt>
373
+ <dd>Width operation: <code>Set to</code> (fixed pixel value) or <code>Multiply by</code> (scale factor).</dd>
374
+ <dt>Width Value <span class="property-type">number|string</span></dt>
375
+ <dd>Width value from number, msg property, flow, or global context. Leave empty for automatic aspect ratio preservation.</dd>
376
+ <dt>Height Mode <span class="property-type">string</span></dt>
377
+ <dd>Height operation: <code>Set to</code> (fixed pixel value) or <code>Multiply by</code> (scale factor).</dd>
378
+ <dt>Height Value <span class="property-type">number|string</span></dt>
379
+ <dd>Height value from number, msg property, flow, or global context. Leave empty for automatic aspect ratio preservation.</dd>
380
+ </dl>
381
+
382
+ <h3>Inputs</h3>
383
+ <dl class="message-properties">
384
+ <dt>payload <span class="property-type">object | array</span></dt>
385
+ <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>
386
+ </dl>
387
+
388
+ <h3>Outputs</h3>
389
+ <dl class="message-properties">
390
+ <dt>payload <span class="property-type">object | array | Buffer</span></dt>
391
+ <dd>Resized image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
392
+ </dl>
393
+
394
+ <h3>Dimension Configuration</h3>
395
+ <p><strong>Operation Modes:</strong></p>
396
+ <ul>
397
+ <li><strong>Set to:</strong> Resizes the dimension to a fixed pixel value (e.g., 800 pixels)</li>
398
+ <li><strong>Multiply by:</strong> Multiplies the original dimension by a factor (e.g., 0.5 for half size, 2.0 for double size)</li>
399
+ </ul>
400
+ <p><strong>Value Sources:</strong> Values can come from fixed numbers, message properties, flow context, or global context using the TypedInput dropdowns.</p>
401
+ <p><strong>Aspect Ratio:</strong> If either width or height is left empty, it will be calculated automatically to maintain the original aspect ratio.</p>
402
+
403
+ <h3>Examples</h3>
404
+ <ul>
405
+ <li><strong>Fixed Size:</strong> Width: Set to 800, Height: Set to 600 → All images resized to 800x600</li>
406
+ <li><strong>Proportional:</strong> Width: Set to 800, Height: (empty) → Width set to 800, height calculated proportionally</li>
407
+ <li><strong>Scale Factor:</strong> Width: Multiply by 0.5, Height: Multiply by 0.5 → Images scaled to half size</li>
408
+ <li><strong>Dynamic Values:</strong> Width: Set to msg.targetWidth → Use width value from message property</li>
409
+ </ul>
410
+
411
+ <h3>Node Interactions</h3>
412
+ <p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
413
+ <p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
414
+ <p><strong>Common Workflows:</strong> Image-in → Resize → other transforms, Array processing → Resize → Array-select</p>
415
+
416
+ <h3>Output Formats</h3>
417
+ <ul>
418
+ <li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
419
+ <li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
420
+ <li><strong>PNG:</strong> Lossless compressed file buffer</li>
421
+ <li><strong>WebP:</strong> Modern compressed format with quality setting</li>
422
+ </ul>
423
+
424
+ <h3>Error Handling</h3>
425
+ <p>The node validates input data and dimensions, displaying warnings for invalid inputs. Processing errors are logged and the message is not propagated.</p>
426
+
427
+ <h3>Performance</h3>
428
+ <p>Uses optimized C++ backend with OpenCV for high-performance processing. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
429
+ </script>