Skip to content
Permalink
Browse files

add read feature to let image manipulation in JS node

  • Loading branch information...
JpEncausseVISEO committed Aug 9, 2019
1 parent 376b61b commit e6ad4291d77a5afdd4bd0eaccf46b08c1ed277fb
Showing with 16 additions and 12 deletions.
  1. +6 −2 node-red-contrib-jimp/node-jimp.html
  2. +9 −9 node-red-contrib-jimp/node-jimp.js
  3. +1 −1 node-red-contrib-jimp/package.json
@@ -14,7 +14,7 @@
'draw-logo': { value: undefined },
'draw-logoType': { value: 'msg'},
'crop-rect': { value: undefined },
'crop-rectType': { value: 'msg'}
'crop-rectType': { value: 'msg'},
},
inputs: 1,
outputs: 2,
@@ -46,6 +46,9 @@
$("#node-input-draw-rect").typedInput('show');
$("#node-input-draw-logo").typedInput('show');
break;
case "read":
$(".read").show()
break;
}
}
@@ -81,6 +84,7 @@
<br>
<label for="node-input-action"><i class="fa fa-navicon"></i> Action</label>
<select id="node-input-action" style="width:70%;">
<option value="read">Read image</option>
<option value="crop">Crop rectangle</option>
<option value="draw">Draw rectangles</option>
</select>
@@ -151,4 +155,4 @@ <h3>References</h3>
</script>
</script>
@@ -15,8 +15,9 @@ module.exports = function(RED) {
RED.nodes.registerType("jimp", register, {});
}


async function input (node, data, config) {

let pathIn = (config.pathInType === "msg") ? helper.getByString(data, config.pathIn) : config.pathIn || 'data/input.jpg' ;
let pathOut = (config.pathOutType === "msg") ? helper.getByString(data, config.pathOut) : config.pathOut || 'data/output.jpg';
let action = config.action || "crop";
@@ -30,7 +31,13 @@ async function input (node, data, config) {
return node.send([null, data])
}

if (action === "draw") {
if (action === "read") {
data._Jimp = Jimp
helper.setByString(data, pathOut, image)
return node.send([data, null])

}
else if (action === "draw") {
let drawRect = (config['draw-rectType'] === "msg") ? helper.getByString(data, config['draw-rect'] || 'payload') : config['draw-rect'];
let drawLogo = (config['draw-logoType'] === "msg" && config['draw-logo']) ? helper.getByString(data, config['draw-logo']) : config['draw-logo'];

@@ -120,9 +127,6 @@ async function input (node, data, config) {

}




else if (action === "crop") {
let cropRect = (config['crop-rectType'] === "msg") ? helper.getByString(data, config['crop-rect'] || 'payload') : config['crop-rect'];

@@ -163,10 +167,6 @@ async function input (node, data, config) {
});
}





// border
async function black_iterator(x, y, offset) {
this.bitmap.data.writeUInt32BE(0x00000088, offset, true);
@@ -1,6 +1,6 @@
{
"name" : "node-red-contrib-viseo-jimp",
"version" : "0.3.1",
"version" : "0.3.2",
"description" : "VISEO Bot Maker - JIMP",
"dependencies" : {
"jimp" : "~0.5.0",

0 comments on commit e6ad429

Please sign in to comment.
You can’t perform that action at this time.