Python fu: Vector stroke scaling awan Junior Gimper Posts: 5 Threads: 2 Joined: Aug 2018 Reputation: 0 Operating system(s): Windows (Vista and later,32-bit) Gimp version: 2.8 08-24-2018, 04:04 PM (This post was last modified: 08-24-2018, 04:07 PM by awan.) How to scale a stroke and keep position at center. red -- original stroke blue -- after scaling using Code: `stroke.scale(0.5, 0.5)` Attached Files Thumbnail(s)     Ofnuts Administrator Posts: 2,878 Threads: 138 Joined: Oct 2016 Reputation: 154 Operating system(s): Linux Gimp version: 2.10 08-24-2018, 04:57 PM (This post was last modified: 08-24-2018, 05:01 PM by Ofnuts.) You have to define the "center" of the stroke Is it the center of the bounding box? The center of mass/centroid? or something else? Once you have determined that, you compute the center for the before/after/strokes, compute the delta vector, and shift the stroke accordingly. Note: the API to translate a stroke (stroke:translate() or its PDB equivalent) only shifts an integer amount of pixels, which makes it unusable in most cases. So you just construct a new stroke by adding the corresponding delta to all coordinates (anchors and tangents). A nice trick is to use a "cycle" generator: Code: ```offsets=itertools.cycle([translateX,translateY]) sourceCoords,closed=sourceStroke.points translatedCoords=[coord+next(offsets) for coord in sourceCoords] translatedStroke = gimp.VectorsBezierStroke(targetPath,translatedCoords,closed)``` But your 2nd image makes me think that you don't want a scaled stroke, but the stroke which is "parallel" to the outer one, which is a different thing. If you tell me what you are trying to do I can find a way to do it differently. If you are on 2.10 there is however an indirect way to have Gimp create that path for you. awan Junior Gimper Posts: 5 Threads: 2 Joined: Aug 2018 Reputation: 0 Operating system(s): Windows (Vista and later,32-bit) Gimp version: 2.8 08-24-2018, 06:01 PM I want something like grow/ shrink selection but for strokes. We specify how much to grow/ shrink. Sorry for my BAD English. Ofnuts Administrator Posts: 2,878 Threads: 138 Joined: Oct 2016 Reputation: 154 Operating system(s): Linux Gimp version: 2.10 08-24-2018, 07:18 PM (08-24-2018, 06:01 PM)awan Wrote: I want something like grow/ shrink selection but for strokes. We specify how much to grow/ shrink. Sorry for my BAD English. I guessed so So, the 2.10 technique, to get the path that is 10px inwards or outwards from your path: - Stroke the path in line mode (new 2.10 API (*)) on a transparent layer, with a 20px width - Alpha to selection: gimp_select_item(layer) - Select>ToPath: plug_in_sel2path(image, drawable) - That path has two strokes, one is inside, one is outside (how to tell: get the length, the shortest is inside) (*) The new 2.10 API, the calls you'll have to use: Code: ```pdb.gimp_context_set_stroke_method(STROKE_LINE) pdb.gimp_context_set_line_cap_style(...) pdb.gimp_context_set_line_join_style(...) pdb.gimp_context_set_line_miter_limit(...) pdb.gimp_context_set_line_width(width) pdb.gimp_drawable_edit_stroke_item(drawable, path)``` awan Junior Gimper Posts: 5 Threads: 2 Joined: Aug 2018 Reputation: 0 Operating system(s): Windows (Vista and later,32-bit) Gimp version: 2.8 08-25-2018, 04:38 AM Your technique will works only if the path is inside the layer and the canvas. Ofnuts Administrator Posts: 2,878 Threads: 138 Joined: Oct 2016 Reputation: 154 Operating system(s): Linux Gimp version: 2.10 08-25-2018, 08:16 AM Right... But you can always copy the path to a suitably big "background" image (no associated Display), do the thing, and copy the path back. By definition of Bézier curves, the path is completely within the rectangle defined by the min and max X and Y coordinates of its anchors or tangents. « Next Oldest | Next Newest »