▲ 4 r/GIMP

Solution on "how to iterate over pixels with python API"

Hi, after a lot of tinkering, I was able to find a solution to the problem presented in this previous thread.

This might be useful to some of you, so here is some example code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# your standard imports, don't forget Gegl
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl # << Gegl needed

# [...] other imports [...]

# needed for this example
import random

#
# [...] some code [...]
#

def randomColors(layer) :
    # example on how to iterate over pixels with Gegl and apply these in batches
    # this is much faster than drawing one by one with Gimp.Drawable.set_pixel()
    # important : the changed pixels can't be undone, it's better to draw them on a new layer
    
    thisBuffer = layer.get_buffer()
    startx = 100
    starty = 100
    sizex =   80 # region size, maybe not too huge? iterate if necessary?
    sizey =   80
    
    rectangleRegion = Gegl.Rectangle.new(startx, starty, sizex, sizey)
    
    bufferSize = sizex * sizey
    bufferData = []
    i = 0
    
    while i < bufferSize :
        
        # attribute some random values to rgb
        r = random.randint(0,255)
        g = random.randint(0,255)
        b =  random.randint(0,255)
        
        bufferData.extend([r, g, b])
        
        i += 1
        
    thisBuffer.set(rectangleRegion, "RGB u8", bufferData) # << this is where we write pixels!
    layer.update(startx, starty, sizex, sizey) # << necessary refresh

Edit:

Not sure about the size of the rectangular region you work on, the variable used to iterate doesn't seem to load more RAM than a regular layer, and GIMP frees the memory slowly after the plugin closes.

reddit.com
u/Scallact — 4 days ago
▲ 10 r/GIMP

How to iterate over pixels with python API?

Hi,

I'm trying to iterate over all the coordinates of an image, and create some calculated pixel values on a new layer. (GIMP 3.xx python API)

I'm currently using the Gimp.Drawable.set_pixel() method, but its very slow (and supposed to be).

I'm struggling to find the right way to do this. I think there was a concept called "regions" in GIMP 2.xx. I understand I have to use a Gegl.Buffer. But from there I'm stuck.

I can't find any definition, or just circular definitions, of what a Gegl buffer is, or any other concept. That's what makes things really difficult.

Does a "buffer" represent the whole drawable? And if it is, how do I extract just a tile and iterate over the pixels?

What is a "shadow buffer"?

What is a "handler"?

What is "the abyss"?

Thanks!

reddit.com
u/Scallact — 7 days ago
▲ 2 r/GIMP

Python API webpages offline

Hi,

I just noticed that the GIMP Python API pages referenced here are not available anymore. The site is online, but GIMP isn't referenced in that site anymore.

This is really annoying, since it's the main reference when writing python plugins. I'll try to use the C API reference for now. Not sure I can work with that. Anyone knows what happened there?

reddit.com
u/Scallact — 12 days ago
▲ 27 r/Xplane

X-Plane devs interview at FSExpo

Ben and Marco interview at FSExpo by FSElite. These guys' passion and talent is really something!

A little more insights into the future scenery engine, the integrated store, and general plans for the future.

youtube.com
u/Scallact — 21 days ago
▲ 38 r/Xplane

X-Plane 12 Platform Update – Live from FSExpo 2026

A first preview of the new scenery engine by Ben Supnik!

youtube.com
u/Scallact — 23 days ago

pl_hexgrid for GIMP 3 has been updated to v0.16 for your hexagonal grids needs

A new version of my python plugin for drawing hexagonal grids with GIMP 3.xx has been released.

The plugin should now be more useful for general use: the hexagons centers alignment with the pixel grid can be bypassed if pixel-perfect rasterization is not needed. Vertical/horizontal lines are still always perfectly aligned to pixels, to avoid annoying blurriness.

As in previous versions, it offers the option to create nicely formatted sample sheet, if you need to choose visually the ideal size, along with the output of useful parameters. A new output is the number of contiguous hexagons and lines the current image can contain.

Anecdotally, for the mathematically inclined, these parameters output, and the filtering ability, can be used to search for the optimal discrete fractions which approximate square root of 3! ;-)

Download by clicking on this link, and the link under "Releases" in the right column. Download the Source code at the bottom, and install it according to the description at the bottom of the Readme.

I invite you to read the documentation, as there are a few non trivial concepts and parameters.

Sample sheet

Hexagonal grid

reddit.com
u/Scallact — 1 month ago
▲ 6 r/GIMP

pl_hexgrid for GIMP 3 has been updated to v0.16 with some notable improvements

The new version of my python plugin for drawing hexagonal grids has been released.

The plugin should now be more useful for general use: the hexagons centers alignment with the pixel grid can be bypassed if pixel-perfect rasterization is not needed. Vertical/horizontal lines are still always perfectly aligned to pixels, to avoid annoying blurriness.

As in previous versions, it offers the option to create nicely formatted sample sheet, if you need to choose visually the ideal size, along with the output of useful parameters. A new output is the number of contiguous hexagons and lines the current image can contain.

Anecdotally, for the mathematically inclined, these parameters output, and the filtering ability, can be used to search for the optimal discrete fractions which approximate square root of 3! ;-)

Download by clicking on this link, and the link under "Releases" in the right column. Download the Source code at the bottom, and install it according to the description at the bottom of the Readme.

I invite you to read the documentation, as there are a few non trivial concepts and parameters.

Sample sheet

Hexagonal grid

reddit.com
u/Scallact — 1 month ago

Cursive font

Hi, I can't seem to find the name of this nice cursive font or some close enough equivalent.

Thanks in advance!

u/Scallact — 2 months ago