| Welcome, Guest |
You have to register before you can post on our site.
|
|
|
| Gimp 3.0 - How to draw stuff with python scripts (pixel by pixel) |
|
Posted by: krokots - 03-04-2026, 05:15 PM - Forum: Scripting questions
- Replies (4)
|
 |
I need help writing some basic script that will draw, for example, a circle, or a rectangle of randomly colored pixels, at a specified X and Y on the selected layer. For now I got this :
Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
gi.require_version("Gimp", "3.0")
gi.require_version("GimpUi", "3.0")
gi.require_version("Gegl", "0.4")
from gi.repository import Gimp, GimpUi, Gegl, GObject, GLib
import sys
class DrawCirclePlugin(Gimp.PlugIn):
def do_set_i18n(self, name):
return False
def do_query_procedures(self):
return ["python-fu-draw-circle"]
def do_create_procedure(self, name):
Gegl.init(None)
procedure = Gimp.ImageProcedure.new(
self, name,
Gimp.PDBProcType.PLUGIN,
self.run,
None,
)
procedure.set_image_types("*")
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE)
procedure.set_menu_label("Draw Circle")
procedure.add_menu_path("<Image>/Filters/Draw")
procedure.set_documentation(
"Draw a filled/outlined circle of a chosen color and radius",
"Draws a circle centred at (center_x, center_y) with the given "
"radius, fill color, and optional stroke outline.",
name,
)
procedure.set_attribution("Your Name", "Your Name", "2024")
procedure.add_int_argument(
"center-x", "Center X", "X coordinate of the circle center (px)",
0, GLib.MAXINT, 100, GObject.ParamFlags.READWRITE,
)
procedure.add_int_argument(
"center-y", "Center Y", "Y coordinate of the circle center (px)",
0, GLib.MAXINT, 100, GObject.ParamFlags.READWRITE,
)
procedure.add_int_argument(
"radius", "Radius", "Radius of the circle in pixels",
1, GLib.MAXINT, 50, GObject.ParamFlags.READWRITE,
)
default_color = Gegl.Color.new("red")
procedure.add_color_argument(
"color", "Fill Color", "Color used to fill (and stroke) the circle",
True, default_color, GObject.ParamFlags.READWRITE,
)
procedure.add_boolean_argument(
"fill", "Fill circle", "Fill the interior of the circle",
True, GObject.ParamFlags.READWRITE,
)
procedure.add_boolean_argument(
"stroke", "Draw outline", "Stroke an outline around the circle",
False, GObject.ParamFlags.READWRITE,
)
procedure.add_int_argument(
"stroke-width", "Outline width", "Outline thickness in pixels",
1, 500, 2, GObject.ParamFlags.READWRITE,
)
return procedure
def run(self, procedure, run_mode, image, drawables, config, run_data):
Gimp.message("A")
if run_mode == Gimp.RunMode.INTERACTIVE:
GimpUi.init("draw_circle")
dialog = GimpUi.ProcedureDialog.new(procedure, config, "Draw Circle")
dialog.fill(None)
if not dialog.run():
dialog.destroy()
return procedure.new_return_values(
Gimp.PDBStatusType.CANCEL, GLib.Error()
)
dialog.destroy()
drawable = drawables[0]
image.undo_group_start()
# draw stuff here
image.undo_group_end()
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
Gimp.main(DrawCirclePlugin.__gtype__, sys.argv)
I see that Drawable class have a method SetPixel, but in the docs it says that undo doesn't work on that. So, how to modify drawable pixels so that undo works ?
|
|
|
| Monochrome png exports as grayscale antialiased (RESOLVED) |
|
Posted by: vtgimp - 02-27-2026, 07:57 PM - Forum: General questions
- Replies (2)
|
 |
I'm presently trying to export a png file as monochrome only, but every time I do, it converts to grayscale antialiased in the saved .png.
Specifically, I save a strictly monochrome 300 dpi bitmap from MTPaint. I can view that image in any image viewer, including in GIMP itself, zoom in, and see that all of the pixels are either black or white. No grays.
In Gimp if I now export that as a png with a new name, the saved png when opened in any viewer now has antialiased greyscale pixels in curved shapes.
If I take that new image back in, and go to colors>image>threshold and again to make it monochrome, succeed at that, then save it as a png, it converts back to antialiased grayscale in the file.
I'd appreciate any advice on how I can simply save a true monochrome .png with Gimp.
Thanks in advance.
|
|
|
| Thank you for Gimp |
|
Posted by: Sampollyt - 02-25-2026, 12:38 PM - Forum: Watercooler
- No Replies
|
 |
I just want to say thank you for Gimp.
Neighbour called and asked for help, scanner on old slow win 10 machine not working.
I convinced her to let me install Gimp.
2 minutes later I was scanning on her system.
I am a Linux dude since long time.
Gimp was always the first stop solution.
Yeah, I am not showing my graphics here - this way, I am not spoiling the thank you thing.
Be assured, I am using Gimp since a very long time.
And since a very long time, it is possible to load .psd into Gimp.
I worked in the graphics "industry" back then and I had to use apple and had to use adobe producs but, when it comes to "graphics", Gimp has been the number one solution for decades.
It can do the job.
It runs on your machine.
There are even ports for android.
thanks goes to the devs and surely to the whole user community base.
thanks
|
|
|
| Smudge tool not working |
|
Posted by: steele - 02-25-2026, 03:05 AM - Forum: General questions
- Replies (4)
|
 |
I recently installed gimp to edit my photos. I end up having to blur a lot of licence plates with the smudge tool. however, every so often, the smudge tool stops smudging, and seems to do nothing instead. I was able to fix this issue a couple of times by resetting the smudge tool, but this time it still isn't working. The only setting I adjust on the smudge tool is the size of it.
Any advice would be much appreciated. For reference, I am using gimp 3.0
|
|
|
| GIMP 3 Python Enums: Definitive Plug-in and Script-Fu Guide |
|
Posted by: chuckhenrich - 02-23-2026, 12:06 PM - Forum: Extending the GIMP
- Replies (6)
|
 |
If you’re developing Python plug-ins or Script-Fu scripts for GIMP 3, you’ll know the frustration of tracking down correct enum values. The official API docs are written for C developers, leaving Python authors to piece things together from source code, forum posts, and trial and error.
I’ve put together what I hope is the definitive reference: every enum available in GIMP 3.0, compiled directly from a live GIMP 3.0.8 instance using a Python-Fu console script. That means the values are guaranteed accurate for that version. And the script is available as a free download so you can regenerate the complete listing for any future GIMP 3 release.
Each enum includes:
- the Python form you actually use in your plug-ins (e.g. Gimp.LayerMode.NORMAL)
- the uppercase PDB identifier, most useful when cross-referencing with the C API docs or porting code from GIMP 2.x Script-Fu scripts
- the raw integer value for legacy Script-Fu work
- the GEGL nickname for serialisation.
The Gimp.LayerMode table also includes the full GEGL operation string.
Every enum has a plain-English description written specifically for Python and Script-Fu developers.
https://www.chuckhenrich.com/gimp-3-pyth...reference/
Comments/suggestions welcome.
|
|
|
|