;; layer-align.scm -*-scheme-*- ;; adapted from ;; file-place.scm -*-scheme-*- ;; see file-place for more info ;; when I'm done I'll put this in the Public Domain ;; until then this is Copyright Alan Horkan ;; you may not modify or distribute it, for personal use only. ;; feel free to remind me. ;; TODO NEEDS more testing and a lot of cleanup but it works (define (script-fu-layer-align image drawable horizontal x-offset vertical y-offset) (let* ( ;; (image2 (car (gimp-file-load 1 file2 file2))) (height2 (car (gimp-drawable-height drawable))) (width2 (car (gimp-drawable-width drawable))) (height (car (gimp-image-height image))) (width (car (gimp-image-width image))) ;; layer type is based on the current image, not the layer being placed (layer-type (car (gimp-drawable-type-with-alpha drawable))) ;; lazy fix(es) for gimp 2, makes keeping back compatibility easier (RGBA_IMAGE RGBA-IMAGE) ; no longer needed ) (gimp-image-undo-group-start image) ;; make undoable ;; flatten the image in case it has more than one layer ;; (gimp-image-flatten image2) ;; now get the drawable ;; (set! drawable2 (car (gimp-image-get-active-drawable image2))) ;; create a new layer, set the file name as the layer name ;; (set! layer-one (car (gimp-layer-new image width2 height2 layer-type layer-name 100 NORMAL))) ;; really should check if it is a layer first (set! layer-one drawable) ;; offsets for the layer (set! x-offset x-offset) (set! y-offset y-offset) ;; TODO rewrite to use cond instead of if statement ;; Horizontal ;; current position + x-offset (same as top edge + x-offset) (if (= 0 horizontal) (set! x-offset (+ x-offset))) ;; left edge + x-offset (same as current position + x-offset) (if (= 1 horizontal) (set! x-offset (+ x-offset))) ;; centre, the usual defualt. same as cut & paste or drag & drop layer (if (= 2 horizontal) (set! x-offset (+ x-offset (/ (- width width2) 2)))) ;; right edge (if (= 3 horizontal) (set! x-offset (+ x-offset (- width width2)))) ;; Vertical ;; current position + x-offset (same as top edge + y-offset) (if (= 0 vertical) (set! y-offset (+ y-offset))) ;; top edge + y-offset (same as current position + y-offset) (if (= 1 vertical) (set! y-offset (+ y-offset))) ;; centre, the usual defualt. same as cut & paste or drag & drop layer (if (= 2 vertical) (set! y-offset (+ y-offset (/ (- height height2) 2)))) ;; bottom edge (if (= 3 vertical) (set! y-offset (+ y-offset (- height height2)))) ;; offset the layer, finally (gimp-layer-set-offsets layer-one x-offset y-offset) (gimp-image-undo-group-end image) (gimp-displays-flush) ) ; close the let statement ) (set! menu-item _"/Layer/Align Layer...") ; old name (script-fu-register "script-fu-layer-align" menu-item ;; Help Description "Takes the current layer and re aligns it. Alignment is based on the image size. " "Alan Horkan. " ; author(s) ;; when finished will be Public Domain. not yet "Alan Horkan, 2004. Copyright " ; rights "2004 08 12 UTC" ; date "" ; supports all image types SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ; is this even necessary? ;; Offsets. ;; Horizontal: [ Current Position ] [ 0 ] pixels ;; Vertical: [ Current Position ] [ 0 ] pixels SF-OPTION _"Horizontal" '( ;_"None " ; 0 _"Current Position " ; 0 _"Left Edge " ; 1 _"Centre " ; 2 _"Right Edge " ; 3 ) SF-ADJUSTMENT _"pixels" '(0 -1000 1000 1 10 0 1) ; no slider SF-OPTION _"Vertical" '( ;_"None " ; 0 _"Current Position " ; 0 _"Top Edge " ; 1 _"Centre " ; 2 _"Bottom Edge " ; 3 ) SF-ADJUSTMENT _"pixels" '(0 -1000 1000 1 10 0 1) ; no slider ) ;; TODO I have no idea if Current Position is any different from Left/Top Edge ;; Need to find out, documentation was too vague and cannot tell from testing