How can I add a plain black line in an image in Gimp in specific pixel coordinates for example between (10,15)->(300,116)?

1 Answer 1


Open the Python console in filters->python->console - get a reference to your image, typing

img = gimp.image_list()[0]

and press enter. Hit the browse button at the botton of the dialog and select gimp- paintbrush-default and hit apply - it will paste a template for calling that function in the Python console - something like this:

>>> pdb.gimp_paintbrush_default(drawable, num_strokes, strokes)

Go back with the arrow keys and edit it so that it reads:

>>> pdb.gimp_paintbrush_default(img.layers[0], 4, [10,15,300,116 ])

And press enter. The img.layers[0] parameter is a reference to the layer - "0" is the top most layer in the image, 1, the second from top to bottom, and so on. (Likewise, in the previous command img = gimp.image_list()[0] retrieves a reference to the last image open in GIMP, and changing the number in square bracktes selects other images).

After the first stroke, you can simply hit up arrow, and get the command back, where you can fill in new coordinates for the line. Also, of course, you can explore the procedures available in the "Browse" button, and use any of them you like.

As few people do this, I'v just noticed a bug: in GIMP 2.8, it ignores the brush size set in the tool options. So you will have to create a brush of the size you want and set it before doing the line.

  • Hello, have you got any link to the documentation of pdb.gimp_paintbrush? Dec 3, 2021 at 18:45
  • All the documentation that is is what show up in the "pdb Browser". I can expand on what is on this answer: The second parameter is the length of the list given in the third parameter (PDB is C based and designed to be cross-language: it does not know about array lengths, although it is automatic in Python). The third parameter is a list where each 2 numbers are a "x,y" coordinate indicating that coordinate was part of a continuous stroke. So, the example here should draw a straight segment with the current colors, brush, settings and dynamics.
    – jsbueno
    Dec 3, 2021 at 19:38
  • There is no programatic way of including per-stroke pressure, tilt, or other parameters in order to get the dynamics effects to activate.
    – jsbueno
    Dec 3, 2021 at 19:39
  • thanks a lot for the quick response, I am just trying to draw complex shapes from a list of coordinates. I was replicating your example, but I have no control on the width of the line, or the color. So I was looking for the doc of the api to navegate it a little before formulating a question on here. I found this other answer stackoverflow.com/a/35874207/1773841, which uses a similar approach, but it only paint dots, instead of the lines of your example. So I am basically trying to find a way to draw lines, having more control over the lines parameters. Still thanks a lot for the help Dec 3, 2021 at 19:49
  • 1
    You have to set brush size and color on the "context" - look for the "gimp-context-set" methods.
    – jsbueno
    Dec 3, 2021 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.