Skip to content

Instantly share code, notes, and snippets.

@morgajel
Last active October 28, 2023 09:49
Show Gist options
  • Save morgajel/7fa8b232a9f05c711e3b to your computer and use it in GitHub Desktop.
Save morgajel/7fa8b232a9f05c711e3b to your computer and use it in GitHub Desktop.
Mass Layer Gimp Python Fu scripts
align multiple layers to the center of an image in gimp
layer = gimp.image_list()[0].layers[0]
image = gimp.image_list()[0]
for layer in gimp.image_list()[0].layers :
x = (image.width - layer.width) / 2
y = (image.height - layer.height) / 2
layer.set_offsets(x, y)
Place each layer in an individual Layer Group
image = gimp.image_list()[0]
layerlist=gimp.image_list()[0].layers
for layer in layerlist:
if not pdb.gimp_item_is_group(layer):
group = pdb.gimp_layer_group_new(image)
group.name = layer.name+" group"
image.add_layer(group, 0)
newlayer = pdb.gimp_layer_copy(layer, 1)
pdb.gimp_image_insert_layer(image, newlayer,group,0)
image.remove_layer(layer)
create a border with the selection->path tool on all layers
I used this to with the erase tool set to 3px with a "hardness 50" brush to remove the burrs from 125 layers in about 30 seconds.
image = gimp.image_list()[0]
layerlist=gimp.image_list()[0].layers
for layer in layerlist:
if not pdb.gimp_item_is_group(layer):
pdb.gimp_image_select_item(image,0,layer)
pdb.plug_in_sel2path(image, layer)
vector_name=pdb.gimp_path_list(image)[1][0]
vec=pdb.gimp_image_get_vectors_by_name(image,vector_name)
vec.name=layer.name+' selection'
pdb.gimp_selection_clear(image)
pdb.gimp_edit_stroke_vectors(layer, vec)
pdb.gimp_path_delete(image, vec.name)
in each layer group, create a few new layers for outlines, details, etc.
image = gimp.image_list()[0]
i=0
for layergroup in gimp.image_list()[0].layers:
if pdb.gimp_item_is_group(layergroup):
i+=1
layergroup.name = "group %s" % i
layer = pdb.gimp_layer_new(image, image.width, image.height, 1, "outline %s" % i, 100.0, 0)
pdb.gimp_image_insert_layer(image, layer, layergroup, 0)
layer = pdb.gimp_layer_new(image, image.width, image.height, 1, "details %s" % i, 100.0, 0)
pdb.gimp_image_insert_layer(image, layer, layergroup, 1)
layer = pdb.gimp_layer_new(image, image.width, image.height, 1, "light and shadow %s" % i, 100.0, 14)
pdb.gimp_image_insert_layer(image, layer, layergroup, 2)
# in each layer group, rename the group name numerically.
image = gimp.image_list()[0]
i = 0
layerlist = gimp.image_list()[0].layers
for layergroup in layerlist:
# each layergroup has 4 layers inside
if pdb.gimp_item_is_group(layergroup):
group=layerlist[i]
group.name="group %s" % i
i+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment