Gimp-Forum.net
pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows (/Thread-pl-stroke-arrows-a-GIMP-3-0-python-plugin-to-draw-simple-arrows)

Pages: 1 2


pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Scallact - 08-12-2025

This is my proposal for a plugin dedicated to a much requested feature in GIMP 3.0: stroke paths with an arrowhead at the end.
It has one genuine feature, compared to other similar plugins (AFAIK): the body path is shortened to ensure that the arrow tip ends up reasonably well aligned with the path's last point.
This apparently trivial feature actually hid a rabbit hole. The requirement of cutting a Bezier curve at a specific point send me through a deep dive into Bezier curves theory and algorithms. :-)

The image below shows a selection of arrowheads styles available:

[attachment=13793]

The documentation is here, and you can download the current version here.

Make sure you place the folder named "pl_stroke_arrows" in the GIMP plug-ins folder inside your profile.
Depending on your operating system, make the file "pl_stroke_arrows.py" inside this folder executable.
The plugin should appear at the bottom of the "Edit" menu.

The plugin has been tested, but some new bugs will probably happen. Please report here, preferably with a downloadable .xcf file to exemplify the case.


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Ofnuts - 08-12-2025

(08-12-2025, 01:47 PM)Scallact Wrote: This apparently trivial feature actually hid a rabbit hole. The requirement of cutting a Bezier curve at a specific point send me through a deep dive into Bezier curves theory and algorithms. :-)
Welcome to the club. Did you see Freya Holmer's videos on YT?


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Scallact - 08-12-2025

(08-12-2025, 09:24 PM)Ofnuts Wrote:
(08-12-2025, 01:47 PM)Scallact Wrote: This apparently trivial feature actually hid a rabbit hole. The requirement of cutting a Bezier curve at a specific point send me through a deep dive into Bezier curves theory and algorithms. :-)
Welcome to the club. Did you see Freya Holmer's videos on YT?

Now that you mention her, I think I saw that video some time ago, but I had no use for it at that time.

The most useful ressources I've found are this page and this algorithm. But I had a lot of tinkering to bring everything together, let alone a few imperfect tries with very home made algorithms. Smile

On the upside, I learned a interesting new things.


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Ofnuts - 08-12-2025

(08-12-2025, 10:55 PM)Scallact Wrote:
(08-12-2025, 09:24 PM)Ofnuts Wrote:
(08-12-2025, 01:47 PM)Scallact Wrote: This apparently trivial feature actually hid a rabbit hole. The requirement of cutting a Bezier curve at a specific point send me through a deep dive into Bezier curves theory and algorithms. :-)
Welcome to the club. Did you see Freya Holmer's videos on YT?

Now that you mention her, I think I saw that video some time ago, but I had no use for it at that time.

The most useful ressources I've found are this page and this algorithm. But I had a lot of tinkering to bring everything together, let alone a few imperfect tries with very home made algorithms. Smile

On the upside, I learned a interesting new things.

I found that if you know how to solve a cubic equation a lot of things becomes a lot simpler...


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Scallact - 08-13-2025

Do you suggest that we can find the exact t parameter of a specific point on the curve by solving a third degree equation? I found a paper about this, but it's unreadable to me given my level of math notation understanding.


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Ofnuts - 08-13-2025

(08-13-2025, 09:20 AM)Scallact Wrote: Do you suggest that we can find the exact t parameter of a specific point on the curve by solving a third degree equation? I found a paper about this, but it's unreadable to me given my level of math notation understanding.

Yes, this is what I did for ofn-path-bend (in fact this is why ofn-path-bend is so fast). Your problem of course is that you have one equation per  Bézier segment, so you are not looking just for t but for t in the adequate segment. However, 1) you can often guess which segment, and 2) in most case for the other segments you won't get a solution for t in [0,1] and when you have one you can check that the solution for ŧ works for bother x and y (and unless you path does a loop there will be only one such pair in it).


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - denzjos - 08-13-2025

(08-12-2025, 01:47 PM)Scallact Wrote: This is my proposal for a plugin dedicated to a much requested feature in GIMP 3.0: stroke paths with an arrowhead at the end.
It has one genuine feature, compared to other similar plugins (AFAIK): the body path is shortened to ensure that the arrow tip ends up reasonably well aligned with the path's last point.
This apparently trivial feature actually hid a rabbit hole. The requirement of cutting a Bezier curve at a specific point send me through a deep dive into Bezier curves theory and algorithms. :-)

The image below shows a selection of arrowheads styles available:



The documentation is here, and you can download the current version here.

Make sure you place the folder named "pl_stroke_arrows" in the GIMP plug-ins folder inside your profile.
Depending on your operating system, make the file "pl_stroke_arrows.py" inside this folder executable.
The plugin should appear at the bottom of the "Edit" menu.

The plugin has been tested, but some new bugs will probably happen. Please report here, preferably with a downloadable .xcf file to exemplify the case.
I tested the plugin on different paths with different parameters and I found no errors. Thanks


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Scallact - 08-13-2025

(08-13-2025, 11:33 AM)denzjos Wrote: I tested the plugin on different paths with different parameters and I found no errors. Thanks

Thanks a lot for your feedback ! This is the first user feedback since I posted it yesterday on different channel, and is really appreciated!

If you have any ideas for features you'd like added, please ask. I can't work on the plugin at the moment, but I'll consider it later on.

Also, I struggled to find a good name for the "anchor offset" parameter, which determines the shape of the back of the arrowhead. I went from "harpoon factor" to "anchor position", and finally "anchor offset", but I'm still not fully convinced. Any ideas?

Ofnuts
(08-13-2025, 09:20 AM)Scallact Wrote: Do you suggest that we can find the exact t parameter of a specific point on the curve by solving a third degree equation? I found a paper about this, but it's unreadable to me given my level of math notation understanding.


Quote:Yes, this is what I did for ofn-path-bend (in fact this is why ofn-path-bend is so fast). Your problem of course is that you have one equation per  Bézier segment, so you are not looking just for t but for t in the adequate segment. However, 1) you can often guess which segment, and 2) in most case for the other segments you won't get a solution for t in [0,1] and when you have one you can check that the solution for ŧ works for bother x and y (and unless you path does a loop there will be only one such pair in it).


OK, I'll look at your code to see how you solved this.

For the segment, I only test the last and second to last segments for the anchor point. If the end of the curve has many packed points, the plugin fails. It's such an edge case that I didn't feel the need to generalize.


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - teapot - 08-13-2025

Hi Scallact, Thank you for the plugin, it's working nicely here and I gave it some tricky paths to test. Well done for tackling splitting the path, it looks a tough call. I especially like that you have a keep-paths option.  One small observation, perhaps a message would be nice when the path cannot be handled as I was sometimes getting a new empty layer in the really tough cases.


RE: pl_stroke_arrows, a GIMP 3.0 python plugin to draw simple arrows - Scallact - 08-13-2025

(08-13-2025, 01:46 PM)teapot Wrote: Hi Scallact, Thank you for the plugin, it's working nicely here and I gave it some tricky paths to test. Well done for tackling splitting the path, it looks a tough call. I especially like that you have a keep-paths option.  One small observation, perhaps a message would be nice when the path cannot be handled as I was sometimes getting a new empty layer in the really tough cases.

Thanks for testing it thoroughly, and thanks for the excellent feedback @teapot! I really appreciate!

Your suggestion for better error feedback was already on my mind. There are a few error cases to handle, and also minor enhancements I'd like to write, but I thought it was already useful and polished enough for publication. :-)

I'll make my todo list a bit more specific about your suggestion.

Enjoy!

P.S: in your try where the arrow was not drawn, do you know if it could be a case where the arrowhead was longer than the path itself?