RafaPolit / node-red-contrib-image-average

Node-RED function node that receives a valid JIMP input and outputs an array with [R, G, B] average values for the image.
MIT License
0 stars 0 forks source link

[FR] Jimp node #1

Open M0ebiu5 opened 6 years ago

M0ebiu5 commented 6 years ago

@RafaPolit What do you think about the idea to make a generic jimp node?

I use now a function node to resize images, but maybe a "jimp node" would be helpful for more people... Here is the sample code:

JIMP.read(msg.payload).then(function(image) {
    msg.image.width = image.bitmap.width;
    msg.image.height = image.bitmap.height;
    image.resize(newwidth,JIMP.AUTO);
    image.quality(quality);
    msg.image2.width = image.bitmap.width;
    msg.image2.height = image.bitmap.height;
    image.getBuffer(image.getMIME(), onBuffer);
}).catch(function (err) {
    // handle an exception
    if (err) throw err;
});

function onBuffer (err, buffer) {
    if (err) throw err;
    msg.payload = buffer;
    node.send(msg);
}
RafaPolit commented 6 years ago

I think it would be interesting, but since someone can just set jimp as a global and have access to it in functions, I'm not sure what one would gain from having a node that just exposes jimp?

M0ebiu5 commented 6 years ago

Sure, but for a novice it's not that easy: First you have to know about jimp - but the node could provide the keywords "scale","crop","resize", "image processing" and so on. One has to install the library manually - as node, the installation routine takes care of the dependencies. One has to fiddle in the settings file...handle the callbacks, parameters, etc

I could try it myself, but i dont have experience with javascript and node creation - so i decided to ask you before.