Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Image stacking
I've been using GIMP for a long time and have some familiarity using BIMP but I recently came across something I need to automate that it can't without scripting or a plugin.  I would like to start with an image with a white background and stack multiple PNG images on top of each other.  For what I need, it will just be the same image stacked on top of itself a variable number of times.  Basically like this:

Start with a new, square dimension image.  
Take a PNG file with a transparent background
Put the first image near the top left corner
Then place another copy a few pixels down and to the right (variable pixels and number of times).

Something tells me this can be done with a script or plugin.  I do have some programming experience and I'm learning Python now, but if a method, plugin, or script exists I would be able to use I would appreciate being steered in the right direction.  Any help you can give me would be greatly appreciated!
You just need to set the offsets of the layers, for instance, to stack the layers in a diagonal:

for i,l in enumerate(image.layers):

Plenty of example Python plugins here. If any questions about them, just ask below.
A non-optimized way to do it :
#!/usr/bin/env python
#-*- coding: utf8 -*-

from gimpfu import *

def your_plug_in_function(image, filename, n_copy, x_start, y_start, h_offset, v_offset):

   offset_x = x_start
   offset_y = y_start

   if not n_copy:

   for i in range(n_copy):
       layer = pdb.gimp_file_load_layer (image, filename)
       pdb.gimp_layer_set_offsets(layer, offset_x, offset_y)
       offset_x += h_offset
       offset_y += v_offset


   "the short plug-in description",
   "the long plug-in description",
   "your name here ",
   "your name here",
   "the year",
   "the plug-in name",
       (PF_IMAGE,    "image",    "active image", None),
       (PF_FILENAME, "filename", "File to load", None),
       (PF_INT,      "n_copy",   "Number of image copies", 5),
       (PF_INT,      "x_start",  "x position of the first layer", 0),
       (PF_INT,      "y_start",  "y position of the first layer", 0),
       (PF_INT,      "h_offset", "Horizontal spacing", 1),
       (PF_INT,      "v_offset", "Vertical spacing", 1),
   your_plug_in_function, menu="<Image>/csoulman")


Save the above code in a file in the appropriate place (sorry, I'm linux addict, I don't know where windows user must save their plug-ins)
Ensure the file has execution rights.
Run GIMP : you will have a menu called 'csoulman' with one entry : 'the plug-in name'

To improve it :
- load the image only once, then use layer.copy()
- check pdb.gimp_file_load_layer success

Forum Jump: