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...

Jeff
-- 
----------------------------------------------------------------------------
Computer Science is as much about computers as astronomy is about telescopes
        -- Edsger Wybe Dijkstra (1930-2002)
----------------------------------------------------------------------------
#!/usr/bin/python

from gimpfu import *

def python_import_image(timg, tdrawable, xoffset, yoffset, infile):
    timg.disable_undo()
    img = pdb.gimp_xcf_load(1,infile,infile)
    for x in img.layers:
        oldX = x.offsets[0]
        oldY = x.offsets[1]
    
        img.remove_layer(x)
        pdb.gimp_drawable_set_image(x,timg)
        timg.add_layer(x,-1)
        x.set_offsets(oldX+xoffset,oldY+yoffset)
    gimp.delete(img)
    timg.enable_undo()

register(
    "python_import_image",
    "Imports Image with Offset",
    "Imports Image with Offset",
    "Jeffrey McBeth",
    "Jeffrey McBeth",
    "Dec 2003",
    "<Image>/Python-Fu/Import",
    "",
    [
    (PF_INT, "xoffset", "X Offset", 0),
    (PF_INT, "yoffset", "Y Offset", 0),
    (PF_FILE, "infile", "Source", "")
    ],
    [],
    python_import_image)

main()
(define (for-each-iterator i length array proc)
  (if (< i length)
      (prog1 
       (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
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user

Reply via email to