# Image manipulation, cut out a non regular shape from an image

**URL:** <https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701>\
**Category:** General\
**Created:** [26 May 2023 05:37 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701 "2023-05-26T05:37:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)\
**Post date:** [26 May 2023 05:37 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701/1 "2023-05-26T05:37:37Z")

</div>

Hi All

I have some images that have areas of interest in that are trapezoid in shape (4 sides, kind of like a pyramid with the top chopped off). Can anyone suggest a way of cutting these shapes out of my image to create a new image? I have looked at node-red-contrib-image-tools but as far as I can see that only allows you to crop an image down to a square.

Thanks

---

<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:** [26 May 2023 07:41 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701/2 "2023-05-26T07:41:05Z")

</div>

Raster images are **always** square/rectangular. It is the use of transparency that gives them irregular shape.

So you can use image-tools to apply a mask or manipulate the pixels to make a "cut out" and save it in a format that supports transparency (e.g. png)

---

<div class="post-metadata">

**Author:** ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)\
**Post date:** [26 May 2023 07:56 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701/3 "2023-05-26T07:56:44Z")

</div>

thanks for the reply.

Yes, I was looking at trying to mask the areas of the image. The mask option that I looked at in node-red-contrib-image-tools required another image to use as a mask. I did try and create a new image and was then going to draw triangles on it to use as a mask but I couldn't see any way of drawing on a new blank image.

Any guidance on how I could mask off triangular areas of the image using just node-red and not using existing images to mask would be much appreciated.

Am I correct in thinking that you are the author of the image-tools node?

---

<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:** [26 May 2023 10:10 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701/4 "2023-05-26T10:10:12Z")

</div>

> [@Roaders](#):
>
> Am I correct in thinking that you are the author of the image-tools node

Yes.

> [@Roaders](#):
>
> Any guidance on how I could mask off triangular areas of the image using just node-red and not using existing images to mask would be much appreciated.

Been some time since I played with image stuff so would need some thought. One solution that jumps out is to scan the image and set pixels transparent. Another would be to dynamically build a mask and apply that.

One last idea, moving away from image-tools is to import [node-canvas](https://www.npmjs.com/package/canvas) into a function node (via the setup tab) and use the canvas `path` to draw an irregular shape and `clip` it. I have an example somewhere & will post it if I can find it.

---

<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:** [25 July 2023 10:10 UTC](https://discourse.nodered.org/t/image-manipulation-cut-out-a-non-regular-shape-from-an-image/78701/5 "2023-07-25T10:10:50Z")

</div>

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