Skip to content

Instantly share code, notes, and snippets.

@vpnwall-services
Last active April 21, 2024 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpnwall-services/a4dc9e5629e326b61a1dd77f1cb4d654 to your computer and use it in GitHub Desktop.
Save vpnwall-services/a4dc9e5629e326b61a1dd77f1cb4d654 to your computer and use it in GitHub Desktop.
[Python Gimp 101] Python Gimp 101 #python #gimp #automation #pythonfu #101

Python Gimp 101

  • Run a python script from Gimp Windows Python-Fu console
# get pwd
os.getcwd()
# run script

cat << EOF > myscript.py
import gimpfu
pdb.gimp_message("Hello world!")
img = gimp.image_list()[0]
print img
c = img.layers[0]
z = pdb.gimp_item_get_children(c)
for item in z:
    print item
    thisLayer = gimp.Item.from_id(item)
    print thisLayer
#    if thisLayer == 'titre':
EOF
execfile("myscript.py")
  • Center and auto calculate grid /2
theImage = gimp.image_list()[0]
centerX = theImage.width/2
centerY = theImage.height/2
gridSpacing = max(theImage.width, theImage.height)/24
pdb.gimp_image_grid_set_offset(theImage, centerX, centerY)
pdb.gimp_image_grid_set_spacing(theImage, gridSpacing, gridSpacing)
pdb.gimp_image_grid_set_style(theImage, GRID_ON_OFF_DASH)
  • Center and auto calculate grid x64
theImage = gimp.image_list()[0]
centerX = theImage.width/2
centerY = theImage.height/2
gridSpacing = max(theImage.width, theImage.height)/64
pdb.gimp_image_grid_set_offset(theImage, centerX, centerY)
pdb.gimp_image_grid_set_spacing(theImage, gridSpacing, gridSpacing)
pdb.gimp_image_grid_set_style(theImage, GRID_ON_OFF_DASH)
  • Move image to absolute coordinates
x_new = 32
y_new = 64
img = gimp.image_list()[4]
layer = img.layers[4]
x_off, y_off = layer.offsets
#pdb.gimp_layer_translate(layer, x_new - x_off, y_new - y_off)
pdb.gimp_layer_set_offsets(layer, x_new, y_new)
  • Get subitem (get children (like layer in grouplayer))
img = gimp.image_list()[0]
c = img.layers[0]
c
<gimp.Layer 'Layer Group'>
pdb.gimp_item_get_children(c)
(1, (4,))
c2 = gimp.Item.from_id(4)
c2
<gimp.Layer 'cam2'>
  • Move group to absolute coordinates
x_new = 32
y_new = 64
img = gimp.image_list()[4]
#layer = img.layers[4]
x_off, y_off = layer.offsets
#pdb.gimp_layer_translate(layer, x_new - x_off, y_new - y_off)
pdb.gimp_layer_set_offsets(layer, x_new, y_new)
  • Get layer (or group) coordinates
for layer in img.layers: print layer.offsets
  • Custom script
c2 = gimp.Item.from_id(15)
pdb.gimp_layer_set_offsets(c2, 32, 64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment