I haven't been on this list in probably 4 years, but up until today, I've
been able to figure out how to get the GIMP to do what I want.

Basically, I have 12 xcf files, each having about 30 layers each.
I want to stitch these files together into one large file without having to
reposition every layer (~360 layers) by hand.

I started the morning discovering you can drag from the layer dialog to
another image and have a copy of the layer be added to the new image.

The problem is that I would have to drag 360 times, and reposition each
layer once drug.

So, I delved back into the world of Script-Fu / Python-Fu.

It looks like a sequence of

  (gimp-image-remove-layer from layer)
  (gimp-drawable-set-image layer to)
  (gimp-image-add-layer to layer -1)
  (gimp-layer-set-offsets layer xoffset yoffset)

on each layer in the from image would do what I want, but it freaks the GIMP
garbage collector out on shutdown.

Any ideas?

Attached are the scheme/python implementations...

Computer Science is as much about computers as astronomy is about telescopes
        -- Edsger Wybe Dijkstra (1930-2002)

from gimpfu import *

def python_import_image(timg, tdrawable, xoffset, yoffset, infile):
    img = pdb.gimp_xcf_load(1,infile,infile)
    for x in img.layers:
        oldX = x.offsets[0]
        oldY = x.offsets[1]

    "Imports Image with Offset",
    "Imports Image with Offset",
    "Jeffrey McBeth",
    "Jeffrey McBeth",
    "Dec 2003",
    (PF_INT, "xoffset", "X Offset", 0),
    (PF_INT, "yoffset", "Y Offset", 0),
    (PF_FILE, "infile", "Source", "")

(define (for-each-iterator i length array proc)
  (if (< i length)
       (proc (aref i))
       (for-each-iterator (+ 1 i) length array proc))

(define (move-layer to from layer xoffset yoffset)
  (gimp-image-remove-layer from layer)
  (gimp-drawable-set-image layer to)
  (gimp-image-add-layer to layer -1)
  (gimp-layer-set-offsets layer xoffset yoffset))

(define (script-fu-image-merge to from xoffset yoffset)
  (let* (img (car (gimp-xcf-load 1 from from)))
    (for-each-iterator 0 (car (gimp-image-get-layers img))
              (cadr (gimp-image-get-layers img))
              (lambda x (move-layer 
                         to from x 
                         (+ (car (gimp-drawable-offsets x)) xoffset) 
                         (+ (cadr (gimp-drawable-offsets x)) yoffset)

#(script-fu-register "move-layer"
#                    "<Toolbox>/Xtns/Script-Fu/Test"
#                    "Image Merge"
#                    "Jeffrey McBeth"
#                    "Jeffrey McBeth"
#                    "Dec 2003"
#                    ""
#                    SF-IMAGE "Destination" 0
#                    SF-IMAGE "Source" 0
#                    SF-DRAWABLE "Layer" 0
#                    SF-VALUE "X Offset" "0"
#                    SF-VALUE "Y Offset" "0")

(script-fu-register "script-fu-image-merge"
                    "<Toolbox>/Xtns/Script-Fu/Image Merge"
                    "Image Merge"
                    "Jeffrey McBeth"
                    "Jeffrey McBeth"
                    "Dec 2003"
                    SF-IMAGE "Destination" 0
                    SF-FILENAME "Source" ""
                    SF-VALUE "X Offset" "0"
                    SF-VALUE "Y Offset" "0")
Gimp-user mailing list

Reply via email to