Dynamically setting property when merging 2 images

@Steve-Mcl

I'm trying to bargraph indicator using your image node

I'm wanting to set srch from outside the node config

how do I do that as this isn';t working for me

[{"id":"799ae55bf5980e54","type":"inject","z":"a5bac9c2d0415401","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["12d88431d0ad0da9","d41e42dda10fd500"]]},{"id":"b498314ed6d950fe","type":"jimp-image","z":"a5bac9c2d0415401","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":470,"y":160,"wires":[["d78b06e0d3df2fe5","d12598a09c7ea102"]]},{"id":"d78b06e0d3df2fe5","type":"image viewer","z":"a5bac9c2d0415401","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":470,"y":200,"wires":[[]]},{"id":"de4b49a7f50d1626","type":"jimp-image","z":"a5bac9c2d0415401","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":430,"y":260,"wires":[["0782e5ff28651de2","d12598a09c7ea102"]]},{"id":"0782e5ff28651de2","type":"image viewer","z":"a5bac9c2d0415401","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":430,"y":300,"wires":[[]]},{"id":"987f3183c36b0946","type":"jimp-image","z":"a5bac9c2d0415401","name":"Merge","data":"payload.green","dataType":"msg","ret":"img","parameter1":"payload.red","parameter1Type":"msg","parameter2":"0","parameter2Type":"num","parameter3":"0","parameter3Type":"num","parameter4":"0","parameter4Type":"num","parameter5":"0","parameter5Type":"num","parameter6":"160","parameter6Type":"num","parameter7":"50","parameter7Type":"num","parameter8":"","parameter8Type":"","sendProperty":"payload","parameterCount":7,"jimpFunction":"blit","selectedJimpFunction":{"name":"blit","fn":"blit","description":"blit the image with another Jimp image at x, y, optionally cropped","parameters":[{"name":"src","type":"","required":true,"hint":"the source image (a Jimp instance)","defaultType":"msg","defaultValue":"payload"},{"name":"x","type":"num","required":true,"hint":"the x position to blit the image"},{"name":"y","type":"num","required":true,"hint":"the y position to blit the image"},{"name":"srcx","type":"num","required":false,"hint":"the x position from which to crop the source image"},{"name":"srcy","type":"num","required":false,"hint":"the y position from which to crop the source image"},{"name":"srcw","type":"num","required":false,"hint":"the width to which to crop the source image"},{"name":"srch","type":"num","required":false,"hint":"the height to which to crop the source image"}]},"x":990,"y":160,"wires":[["fcd9f7faebfcfd30"]],"icon":"font-awesome/fa-image"},{"id":"fcd9f7faebfcfd30","type":"image viewer","z":"a5bac9c2d0415401","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":1130,"y":160,"wires":[[]]},{"id":"12d88431d0ad0da9","type":"change","z":"a5bac9c2d0415401","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"w\":160,\"h\":100,\"background\":\"#FF0000\"}","tot":"json"},{"t":"set","p":"topic","pt":"msg","to":"red","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":160,"wires":[["b498314ed6d950fe"]]},{"id":"d41e42dda10fd500","type":"change","z":"a5bac9c2d0415401","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"w\":160,\"h\":100,\"background\":\"#00FF00\"}","tot":"json"},{"t":"set","p":"topic","pt":"msg","to":"green","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":260,"wires":[["de4b49a7f50d1626"]]},{"id":"c70e526d0d6f25c0","type":"debug","z":"a5bac9c2d0415401","name":"Look in the available properties in the debug side bar","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":940,"y":360,"wires":[]},{"id":"d12598a09c7ea102","type":"join","z":"a5bac9c2d0415401","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":630,"y":160,"wires":[["c70e526d0d6f25c0","31c61d8a86547c70"]]},{"id":"31c61d8a86547c70","type":"change","z":"a5bac9c2d0415401","name":"","rules":[{"t":"set","p":"parameters","pt":"msg","to":"[0,0,0,0,160,80]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":160,"wires":[["987f3183c36b0946"]]}]

?

?

Not following Simon sorry.

Can you clarify pls? Perhaps showing a mock image of what you're trying to achieve with some annotations would help?

The last image after the merge shows 50/50 red/green as set in the merge node srch parameter

how can I vary that from outside the node config?

Trying to make a poor mans bargraph indicator :slight_smile:

No urgent reply needed :slight_smile:

Something like this?

chrome_LYPo4yQPFO

[{"id":"7d8460a8e7cc5092","type":"inject","z":"6e46a349d744ceaa","name":"srch 10","props":[{"p":"payload"},{"p":"srch","v":"10","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":610,"y":2460,"wires":[["4d6b8738aa3dd8f3"]]},{"id":"4c0a3e3afe32b996","type":"image viewer","z":"6e46a349d744ceaa","name":"","width":"80","data":"payload","dataType":"msg","active":true,"x":1270,"y":2660,"wires":[[]]},{"id":"9aa55479a8a806ea","type":"inject","z":"6e46a349d744ceaa","name":"srch 50","props":[{"p":"payload"},{"p":"srch","v":"50","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":610,"y":2500,"wires":[["4d6b8738aa3dd8f3"]]},{"id":"aeed62794d9e5a22","type":"inject","z":"6e46a349d744ceaa","name":"srch 90","props":[{"p":"payload"},{"p":"srch","v":"90","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":610,"y":2540,"wires":[["4d6b8738aa3dd8f3"]]},{"id":"8a5acac070aadc19","type":"jimp-image","z":"6e46a349d744ceaa","name":"Merge msg.red + msg.green","data":"green","dataType":"msg","ret":"img","parameter1":"red","parameter1Type":"msg","parameter2":"0","parameter2Type":"num","parameter3":"0","parameter3Type":"num","parameter4":"0","parameter4Type":"num","parameter5":"0","parameter5Type":"num","parameter6":"160","parameter6Type":"num","parameter7":"srch","parameter7Type":"msg","parameter8":"","parameter8Type":"","sendProperty":"payload","parameterCount":7,"jimpFunction":"blit","selectedJimpFunction":{"name":"blit","fn":"blit","description":"blit the image with another Jimp image at x, y, optionally cropped","parameters":[{"name":"src","type":"","required":true,"hint":"the source image (a Jimp instance)","defaultType":"msg","defaultValue":"payload"},{"name":"x","type":"num","required":true,"hint":"the x position to blit the image"},{"name":"y","type":"num","required":true,"hint":"the y position to blit the image"},{"name":"srcx","type":"num","required":false,"hint":"the x position from which to crop the source image"},{"name":"srcy","type":"num","required":false,"hint":"the y position from which to crop the source image"},{"name":"srcw","type":"num","required":false,"hint":"the width to which to crop the source image"},{"name":"srch","type":"num","required":false,"hint":"the height to which to crop the source image"}]},"x":880,"y":2660,"wires":[["4c0a3e3afe32b996"]],"icon":"font-awesome/fa-image"},{"id":"46c730c1f55f238d","type":"jimp-image","z":"6e46a349d744ceaa","name":"Create top image","data":"payload","dataType":"msg","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"red","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":1090,"y":2500,"wires":[["47f691d411e667ad"]]},{"id":"3bed55b6569bb12a","type":"change","z":"6e46a349d744ceaa","name":"setup top","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"w\":160,\"h\":100,\"background\":\"#FF0000\"}","tot":"json"},{"t":"set","p":"payload.background","pt":"msg","to":"tc","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":2500,"wires":[["46c730c1f55f238d"]]},{"id":"47f691d411e667ad","type":"image viewer","z":"6e46a349d744ceaa","name":"","width":"40","data":"red","dataType":"msg","active":true,"x":1270,"y":2500,"wires":[["9943c6baa3eab5db"]]},{"id":"098b32704a7ba2eb","type":"jimp-image","z":"6e46a349d744ceaa","name":"Create base image","data":"payload","dataType":"msg","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"green","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":1090,"y":2580,"wires":[["33ab7893555acb37"]]},{"id":"33ab7893555acb37","type":"image viewer","z":"6e46a349d744ceaa","name":"","width":"40","data":"green","dataType":"msg","active":true,"x":1270,"y":2580,"wires":[["8a5acac070aadc19"]]},{"id":"9943c6baa3eab5db","type":"change","z":"6e46a349d744ceaa","name":"setup base","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"w\":160,\"h\":100,\"background\":\"#00FF00\"}","tot":"json"},{"t":"set","p":"payload.background","pt":"msg","to":"bc","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":2580,"wires":[["098b32704a7ba2eb"]]},{"id":"6dcfc6555a908f58","type":"change","z":"6e46a349d744ceaa","name":"","rules":[{"t":"set","p":"bc","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":2360,"wires":[[]]},{"id":"3e70c84616046a68","type":"inject","z":"6e46a349d744ceaa","name":"set base colour blue","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"#0000FF","payloadType":"str","x":1050,"y":2340,"wires":[["6dcfc6555a908f58"]]},{"id":"324693771e1603db","type":"inject","z":"6e46a349d744ceaa","name":"set base colour green","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"#00FF00","payloadType":"str","x":1060,"y":2380,"wires":[["6dcfc6555a908f58"]]},{"id":"4cb31650492d4b80","type":"change","z":"6e46a349d744ceaa","name":"","rules":[{"t":"set","p":"tc","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":2360,"wires":[[]]},{"id":"4cd65c749896446e","type":"inject","z":"6e46a349d744ceaa","name":"set top colour red","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"#FF0000","payloadType":"str","x":650,"y":2340,"wires":[["4cb31650492d4b80"]]},{"id":"430af178539fe05b","type":"inject","z":"6e46a349d744ceaa","name":"set top colour silver","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"#d1d1d1","payloadType":"str","x":650,"y":2380,"wires":[["4cb31650492d4b80"]]},{"id":"4d6b8738aa3dd8f3","type":"junction","z":"6e46a349d744ceaa","x":780,"y":2500,"wires":[["3bed55b6569bb12a"]]}]

Key to working with images in Node-RED is to minimise (completely eliminate where possible) branches as each wire branch creates an expensive clone of the image data.

Look at my flow, see how i utilise properties in the msg to store the top and base images and carry them along a single flow until the last node.

That's why the image viewer node has an output. I know its not pretty but the larger the image, the more it becomes important.

2 Likes

Just going thru your flow one step at a time :slight_smile:

Why is msg.payload.background still set to "#FF0000" at this point?

Why isn't it the saved flow.tc image?

I don't know what flow.tc is set to in your context so I can't comment.

Does it all work for you as it did for me in the demo gif?

Sorry for noise ! Usual PEBKAC at this end

It works lovely - I was just trying to go thru one step at a time to make sure I new what was going on and failed at my 1st step

I'm going to blame the fact that I had a bad nights sleep and its early in the morning :slight_smile:

2 Likes

And I now see my error in my orig - wasn't setting srch (and the using in merge) correctly

Do going back to your point about memory usuage

Instinctively, I'd now write your flow as

to avoid one of the NR gods having apoplexy at a wire sticking thru an output switch :slight_smile:

is there still a penalty if the viewer switch is off?

Yes. The message is still transmitted down the wire.

And this conversation now dovetails nicely into another thread...

Does this gods name rhyme with "wave" :wink:

@dceejay

1 Like

That thread is what made me try this - to come up with a method of having a bargraph "guage" but using your existing viewer node :slight_smile:

Without breaking any rules ..

[{"id":"463a4a791ee10b35","type":"inject","z":"d418230481b87e35","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":1080,"wires":[["c061dffdc7f953c0"]]},{"id":"c061dffdc7f953c0","type":"random","z":"d418230481b87e35","name":"","low":1,"high":"100","inte":"true","property":"payload","x":380,"y":1080,"wires":[["02081e637f75357b"]]},{"id":"02081e637f75357b","type":"function","z":"d418230481b87e35","name":"level me","func":"const min = 0\nconst max = 100\n\nconst val = msg.payload\nlet result = ''\n\nfor(let i = 0;i<20;++i){\n    if(i<val/5){\n        result += '|'\n    }\n    else{\n        result += ' '\n    }\n}\nresult += \" \"+val\n\nnode.status({fill:'', shape:'ring' , text:result})\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":1080,"wires":[[]]}]

image

4 Likes

And don't they look lovely working together :slight_smile:
gauge

2 Likes

2 Likes

Yes they do

@cymplecy Don't forget you can also use unicode chars... Unicode Block “Block Elements”

1 Like

And you can print the value over image too

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.