Hello,
I wanted to use Jimp (which is installed with node-red-contrib-image-tools) inside function node. My usage is to get pixel array out of png image (tried to write my own png decoder, but had trouble with the compression chunks, even with zero compression ...). Unfortunately I am not able to load the image. I use this import in setup of function:
but then in code when I want to use Jimp.read() function, I get the error "TypeError: Jimp.read is not a function"
I never used the modules so maybe I made some mistake there.
Also I found someone imports Jimp through global context, but thought the module would be more appropriate.
Thanks for any response
Im on Node-RED 4.0.5
Node.js 20.18.1
Can you try with Jimp.Jimp.read
?
There is no need to import Jimp.
What you are doing here is (unnecessarily) importing a DIFFERENT version of Jimp to the version image-tools installs.
The image node already outputs the image (and its properties) so you can access the pixel data see this example where I set msg.image
in the image node and in the function "colorise" I call setPixelColor
: How to generate an image from the 8x8 raw heat map data of an AMG8833 thermal sensor - #8 by Steve-Mcl
e.g.
Thank you,
now I dont get any errors, but the code seems not running. When I run this code:
Jimp.Jimp.read("/home/pi/img.png", (err, img) => {
node.warn("test");
node.send({payload: "test"});
if (err) throw err;
});
nothing is shown in debug.
Thank you for response. In fact I wasnt importing different version, but the same one from image-tools.
You are right, when I select output image type from image-tools node, there is the bitmap array inside of image object which I can use. I didnt find it before, I thought its only some object for the viewer node.
Thank you
That is incorrect.
When you enter jimp as a module into the function node it ends up installing jimp@latest:
Installing module: jimp, version: latest
The Jimp version in image-tools
is from before they completely broke everything in v1.x
image-tools is currently getting a re-write (v3 branch on GitHub) that upgrades everything (but it is a pain since pretty much EVERYTHING changed from v0.x to v1.x)! That's why i said you are unnecessarily adding a reference.
1 Like
OK,
when I opened the setup page first time and clicked on the module combo box, the jimp was already there, so I thought its the same jimp ... but idk if it installed the latest version