# Using Jimp in function node

**URL:** https://discourse.nodered.org/t/using-jimp-in-function-node/96061
**Category:** General
**Tags:** function-node
**Created:** [17 March 2025 11:27 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061 "2025-03-17T11:27:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mima232](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@mima232](https://discourse.nodered.org/u/mima232)
#### Post date: [17 March 2025 11:27 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/1 "2025-03-17T11:27:55Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b4e8b7f810ef8548b78d0035a4a5658476363c96.png)  
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

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [17 March 2025 11:30 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/2 "2025-03-17T11:30:51Z")

</div>

Can you try with `Jimp.Jimp.read` ?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 March 2025 11:39 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/3 "2025-03-17T11:39:25Z")

</div>

> [@mima232](#):
>
> 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

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](https://discourse.nodered.org/t/how-to-generate-an-image-from-the-8x8-raw-heat-map-data-of-an-amg8833-thermal-sensor/31604/8)

e.g.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0953be154308e8df81853eeb9c861f91f572df28.png)

---

<div class="post-metadata">

### Author: ![mima232](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@mima232](https://discourse.nodered.org/u/mima232)
#### Post date: [17 March 2025 12:29 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/4 "2025-03-17T12:29:09Z")

</div>

Thank you,  
now I dont get any errors, but the code seems not running. When I run this code:

```auto
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.

---

<div class="post-metadata">

### Author: ![mima232](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@mima232](https://discourse.nodered.org/u/mima232)
#### Post date: [17 March 2025 12:36 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/5 "2025-03-17T12:36:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 March 2025 12:45 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/6 "2025-03-17T12:45:26Z")

</div>

> [@mima232](#):
>
> In fact I wasnt importing different version, but the same one from image-tools.

That is incorrect.

When you enter jimp as a module into the function node it ends up installing jimp@latest:

```bash
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.

---

<div class="post-metadata">

### Author: ![mima232](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@mima232](https://discourse.nodered.org/u/mima232)
#### Post date: [17 March 2025 14:05 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/7 "2025-03-17T14:05:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [31 March 2025 14:05 UTC](https://discourse.nodered.org/t/using-jimp-in-function-node/96061/8 "2025-03-31T14:05:51Z")

</div>

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