Thread Rating:
• 1 Vote(s) - 5 Average
• 1
• 2
• 3
• 4
• 5
 Paths Basics Ofnuts Administrator Posts: 5,196 Threads: 225 Joined: Oct 2016 Reputation: 449 Operating system(s): Linux Gimp version: 2.10 11-27-2016, 10:54 PM (This post was last modified: 08-14-2020, 11:17 PM by Ofnuts.) Paths Basics This is a short introduction to paths (also known as "vectors") as Gimp uses them. Bézier Curves In the sixties, Pierre Bézier was looking for a way to generate smooth curves in Computer-Aided Graphics and eventually settled on curves that have since been named after him. There are many types of Bézier curves but Gimp, as most graphics programs, uses the "cubic" ones. These are simple curves defined by: Two points called the "anchors" (A1 and A2, below) that are the starting and ending point of the curve. Two control points called the "handles" (H1 and H2, below), that indicate: Using the line between the anchor and the handle: the general direction of the curve near the corresponding anchor. For the mathematically-oriented this line is the tangent of the curve on the anchor. Using the distance between the anchor and the handle: how much the curve follows the direction of the handle.     If we bring H1 closer to A1 and drag H2 further from A2:     The closer the handle is to the anchor, the less influence it has on the shape of the whole curve. The limit is when the handle coincides with the anchor: in that case there is no tangent defined, and the general direction of the curve near the anchor is determined by the other handle. When there are no tangents defined at both ends, the curve becomes the straight line between the two anchors. In Gimp's path editor, anchors are usually created without handles, or, more accurately, with handles over the anchors, so a sequence of points creates a polygon, until you start dragging the handles out of the anchors. We can even have loops and cusps:     Some nice properties of Bézier curves The Bézier curves have a few properties worth remembering: The whole curve is always inside the convex polygon defined by the two anchors and the two handles. They are "compatible" with the simpler geometric transforms (a.k.a. "affine transforms") which are those that are found in Gimp's toolbox: shear, rotation, scale, flip(*). Which means that these two sequence of actions are equivalent: "stroke" the curve to create a bitmap layer use a transform tool on the layer and use a transform tool on the curve (in "Path" mode) "stroke" the curve to create a bitmap layer but of course the curve obtained with the second method will be sharper.   (*) The perspective transform isn't an affine transform, and in some cases, the two methods above would yield slightly different results, but in practice this still works most of the time, especially with paths obtained by Layer>Text to path. Strokes As elegant as they are, Bézier curves are not powerful enough to describe real-life curves such as the outline of characters. So more arbitrary curves are implemented by stringing together Bézier curves, the ending anchor of a curve also being the starting anchor of the next:     Each anchor becomes associated with two handles, one for the curve that ends on it (the "backward" handle) and one for the curve that starts from it (the "forward" handle). If these handles are aligned (A2) the curve remains smooth, but cusps can be obtained with handles on the same side (A3), and loops are obtained by interchanging the handles (or rotating them both by half a turn around the anchor)(A4). In practice the stroke is defined and handled as a series of triplets of points, each triplet being made of the backward handle, the anchor, and the forward handle:     When doing so, the first and last anchor have one extra handle (backward for the first, forward for the last). These handles have a purpose: if you connect two strokes, the line between the two strokes is the Bézier curve controlled by these handles. Likewise, if you cut a stroke by Ctrl-Shift-clicking a segment to delete it, the new final anchors of the two resulting strokes keep the handles that controlled the removed segment. Open and closed strokes A similar principle is used to "close" strokes. When the stroke is marked "closed" (and this is just a supplemental closure indicator, Gimp doesn't add any point), an additional Bézier curve is generated from the last anchor to the first, under the control of these extra handles.     In Gimp, you mark the stroke as "closed" by connecting the first and last anchors. Once the stroke is closed it is impossible to distinguish the actual first and last anchors, and in the picture above, the stroke could just as well start on A3 and end on A2. It is however possible to force Gimp to consider two anchors as the first and the last: Given a stroke like this (the red part is the Bézier curve generated by the closure):     Open the stroke by deleting the segment between the two target anchors (2 and 3). These two anchors becomes the start and end of the open stroke. The handles are preserved:     Now, reconnect these anchors. The Bézier curve is regenerated, so the stroke shape is the same as initially, but the start and end anchors are the ones delimiting the temporarily deleted segment.     This technique can be generalized to have the stroke start on any point. Just add an anchor on the path by Control-licking the path where you want the stroke to start. Then use the technique above, removing and adding a segment that ends on that new anchor. Stroke direction Sometimes, the direction of the stroke is important. The stroke 1-to-4 above has the very same shape as the stroke obtained from the same triplets, ordered 4-to-1. But there are cases where the direction counts, for instance:   Using the "Text-along-path" function Rendering the stroke by painting it with a gradient Well, tough luck, there is nothing in out-of-the-box Gimp that will tell you the stroke direction, or let you change it. It just happens that Gimp doesn't usually change a stroke direction, so the first point of the stroke is usually the one you created first. But you have little control on the direction of strokes generated by Gimp (Layer>Text to path, or Select>To path). But there are scripts available to help with this. Paths Strokes are powerful, but have a restriction: they are continuous lines. So, a single stroke is not powerful enough to describe complex curves such as the one needed to describe text. Enter the paths, that are nothing more than a bunch of strokes taken together. For instance, the word "hobbit" is made of 10 strokes: One singe stroke for the 'h'. Two strokes for the "o", the outer outline and the inner hole. Two strokes for each "b", the outer outline and the inside for the loops. Two strokes for the 'i', one for the body and one for the dot (a.k.a. "tittle"). One singe stroke for the 't'. In uppercase, 'HOBBIT' is 11 strokes, since the 'B's have one more loop but the 'I' loses the dot. Path handling in Gimp Gimp processes the path as a whole, there is no way to restrict its action to specific strokes. The path is associated to the canvas, not to a specific layer. A path can have points that lie outside of the canvas Coordinates of anchors and handles are not restricted to integer pixels. Sub-pixel paths are possible Selection from paths where strokes are not disjoint follows an 'even-odd' rule. Starting un-selected from a border, the selection state changes each time it crosses a line. This is neither and intersection nor a union, but a rule that creates the expected selection on text (unless characters overlap). Krikor Obsessive Gimper Posts: 766 Threads: 63 Joined: Aug 2018 Reputation: 52 Operating system(s): Windows (Vista and later) Gimp version: 2.10 05-06-2019, 04:47 PM Quote:For instance, the word "hobbit" is made of 10 strokes: One singe stroke for the 'h'. Two strokes for the "o", the outer outline and the inner hole. Two strokes for each "b", the outer outline and the inside for the loops. Two strokes for the 'i', one for the body and one for the dot (a.k.a. "tittle"). One singe stroke for the 'h'. In uppercase, 'HOBBIT' is 11 strokes, since the 'B's have one more loop but the 'I' loses the dot. Just pointing the last 'h', where it missing the 't'.  Although it does not change the 10 strokes at all. Ofnuts Administrator Posts: 5,196 Threads: 225 Joined: Oct 2016 Reputation: 449 Operating system(s): Linux Gimp version: 2.10 05-06-2019, 07:55 PM Yeah. Fixed FlutteringBy Junior Gimper Posts: 9 Threads: 1 Joined: Nov 2018 Reputation: 0 Operating system(s): Windows (Vista and later) Gimp version: 2.10 05-11-2019, 07:20 PM Thanks so much for the clear explanations, Ofnuts.... Much appreciated by us newbies.... Gimp_Rules Newbie Posts: 3 Threads: 0 Joined: Oct 2019 Reputation: 0 Operating system(s): Windows (Vista and later,32-bit) Gimp version: 2.10 03-14-2020, 03:52 PM WOW!!! Brilliant! Agree with FlutteringBy, a great intro to paths for us newbies. Major Kudos! I am restoring an old pinball machine that has a playfield in poor condition. I scanned it, and have been using Gimp to repair the scans with the goal of creating stencils for at least the black keylines that separate the areas of color. The straight lines are easy, but I'd struggled with curved ones, trying to freehand the fixes. Not a good idea - I'm fairly steady, but the results were poor, and I had to keep trying to fix things. Until I found this, my attempts to use the path tool were unsuccessful since I had no idea how they worked. Once I read this, though, I was able to quickly path and stroke the curved keylines. I'm lucky in that they are pretty simple curves, just the arc of a circle, so I only needed the two endpoints. Again, thanks Ofnuts for the easy to understand intro! Ofnuts Administrator Posts: 5,196 Threads: 225 Joined: Oct 2016 Reputation: 449 Operating system(s): Linux Gimp version: 2.10 12-27-2022, 11:08 PM Two very nice videos if you want to know a bit more about Bézier curves (some math formulas may be flashing before you eyes, but there are also very nice animations): Some more (the first 40mn) « Next Oldest | Next Newest »

Forum Jump: