Attach text on path in GIMP
I'm discovering the gimp API for few days now (using python-fu) and I actually enjoy it. However there is something I can't manage to do : attach a text on a path.
Using the user interface to perform it is quite easy (create a path > create a text > click on text along path in toolbox)... but, as you might expect, I ain't love when things are easy. That's why I'm trying to do it using python.
Here is what I already managed to do :
- create a layer
- add a path on it
- create a new text
- display the whole thing
All I have to do right now is learning how to make my text follow the path.
Help would 开发者_运维百科be warmly appreciated.
Thank you
After hours and hours of research on the right side of Internet (the one with no naked people on it) I haven't found so much about my question. That's why I decided to look at Gimp source code in order to know how the magical "text along path" actually works... and it seems nothing has been made to make this action available via pdb.
After that, in order to be sure, I've asked on the gimp developers' mailing list and someone (I don't know if I'm allowed to tell his name right here) replied me with that :
The "text along path" function is basically a hack, and was never intended to be a final product. A proper text-along-path function would allow the path to be changed and alter the text accordingly. The way that the warped text is rendered is also less than ideal. Because the plan was always that the functionality would change, no PDB hook was ever created for it.
Another told me how to create my own "text along path" plugin :
However, as far as I know, the Bezier strokes in a path have the following property, applying an affine transform to their control points and handles is equivalent to applying the same transform to every point of the curve. So you can do something like this:
- determine a "reference path", that is, a straight path along the text (or running though the middle of it)
- for each stroke iterate the control points, and on each point ("C"):
- determine projection on reference path (distance from origin of reference path) (elt's call it "R") and distance to it
- find the corresponding point on the target path (pdb.gimp_path_get_point_at_dist()), "R'"
- find the position of the new control point C': same distance to target path, on perpendicular
- compute the position of the handles:
- compute dx/dy between H and C
- compute equivalent position H' from the new control point C'
- apply rotation, centered on C' with an angle that is the direction of the target path in R' (as returned by earlier gimp_path_get_point_at_dist()) to produce new handle position (H")
- repeat for 2nd handle
- add the triplet C', H"1, H"2 to the new stroke
Then he encouraged me to look at two plugins doing things similar with vectors, named ribbon-path and slinky, and available on http://gimp-path-tools.sourceforge.net/
I hope (thanks to these two guys) this post will help.
精彩评论