; GIMP - The GNU Image Manipulation Program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ; ; ; Creates animations from single layers. A script version of the "Move Layer" Option ; found within the GIMP Animation Plugin. ; ; The script can be found on an open image in GIMP 2.6 under: Filters > Animation > Move Layer... ; ; Define the Function (define (fp-script-fu-move-layer-anim image layer frames direction pingPong pingCopy layerHandle startX startY endX endY addPath blendMode opacity fillOption ) ; Declare the Variables (let* ( (height 0) (width 0) (copyLayer 0) (origSelect 0) (wrap 0) (x-dir (cond (( equal? direction 0 ) 0) (( equal? direction 1 ) 0) (( equal? direction 2 ) -1) (( equal? direction 3 ) 1) (( equal? direction 4 ) -1) (( equal? direction 5 ) 1) (( equal? direction 6 ) -1) (( equal? direction 7 ) 1) ) ) (y-dir (cond (( equal? direction 0 ) -1) (( equal? direction 1 ) 1) (( equal? direction 2 ) 0) (( equal? direction 3 ) 0) (( equal? direction 4 ) -1) (( equal? direction 5 ) -1) (( equal? direction 6 ) 1) (( equal? direction 7 ) 1) ) ) (step-x 0) (step-y 0) (offset-x 0) (offset-y 0) (mode-lut '#(0 1 3 15 4 5 16 17 18 19 20 21 6 7 8 9 10 11 12 13 14)) (vectors 0) (pathLength 0) (dist 0) (distInc 0) (points (cons-array 12 'double)) (numLayers 0) (layerID 0) (stackPos 1) (fillColor 0) ) (gimp-context-push) (gimp-undo-push-group-start image) (set! origSelect (car (gimp-selection-save image))) (gimp-selection-none image) (set! width (car (gimp-drawable-width layer))) (set! height (car (gimp-drawable-height layer))) (gimp-layer-add-alpha layer) (gimp-layer-set-mode layer (vector-ref mode-lut blendMode)) (gimp-layer-set-opacity layer opacity) (if (= pingPong TRUE) (set! frames (ceiling (/ frames 2))) ) (if (= direction 9) (begin (set! startX (car (gimp-drawable-offsets layer))) (set! startY (cadr (gimp-drawable-offsets layer))) ) ) (if (= direction 10) (set! vectors (car (gimp-image-get-active-vectors image))) ) (if (> direction 7) (begin (if (or (= direction 8)(= direction 9)) (begin (set! vectors (car (gimp-vectors-new image "New Path"))) (aset points 0 startX) (aset points 1 startY) (aset points 2 startX) (aset points 3 startY) (aset points 4 startX) (aset points 5 startY) (aset points 6 endX) (aset points 7 endY) (aset points 8 endX) (aset points 9 endY) (aset points 10 endX) (aset points 11 endY) (gimp-vectors-stroke-new-from-points vectors 0 12 points FALSE) ) ) (set! pathLength (trunc (car (gimp-vectors-stroke-get-length vectors 1 1)))) (set! distInc (/ pathLength (- frames 1))) (if (and (or (= direction 8)(= direction 9)) (= addPath TRUE)) (gimp-image-add-vectors image vectors -1) ) (while (>= frames 0) (set! offset-x (car (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1))) (set! offset-y (cadr (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1))) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (if (> frames 0) (gimp-image-add-layer image copyLayer -1) ) (cond ( (= layerHandle 1) ; top middle (set! offset-x (- offset-x (/ width 2))) ) ( (= layerHandle 2) ; top right (set! offset-x (- offset-x width)) ) ( (= layerHandle 3) ; middle left (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 4) ; center (set! offset-x (- offset-x (/ width 2))) (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 5) ; middle right (set! offset-x (- offset-x width)) (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 6) ; bottom left (set! offset-y (- offset-y height)) ) ( (= layerHandle 7) ; bottom middle (set! offset-x (- offset-x (/ width 2))) (set! offset-y (- offset-y height)) ) ( (= layerHandle 8) ; bottom right (set! offset-x (- offset-x width)) (set! offset-y (- offset-y height)) ) ) (gimp-layer-set-offsets copyLayer offset-x offset-y) (if (> frames 0) (gimp-layer-resize-to-image-size copyLayer) ) (set! frames (- frames 1)) (set! dist (+ dist distInc)) ); while closure ;(gimp-image-remove-layer image layer) ); begin closure (begin (set! step-x (* x-dir (/ width frames))) (set! step-y (* y-dir (/ height frames))) (set! offset-x step-x) (set! offset-y step-y) (set! frames (- frames 1)) (while (>= frames 1) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (gimp-image-add-layer image copyLayer -1) (if (= fillOption 0) (begin (set! wrap TRUE) (set! fillColor 1) ) ) (if (= fillOption 1) (begin (set! wrap FALSE) (set! fillColor 0) ) ) (if (= fillOption 2) (begin (set! wrap FALSE) (set! fillColor 1) ) ) (gimp-drawable-offset copyLayer wrap fillColor offset-x offset-y) (set! offset-x (+ offset-x step-x)) (set! offset-y (+ offset-y step-y)) (set! frames (- frames 1)) ); while closure ); begin closure direction < 7 ); if direction > 7 closure (if (= pingPong TRUE) (begin (if (= pingCopy TRUE) (set! numLayers (- (car (gimp-image-get-layers image)) 1)) (set! numLayers (car (gimp-image-get-layers image))) ) (set! layerID (cadr (gimp-image-get-layers image))) (while (> numLayers 2) (set! layer (car (gimp-image-set-active-layer image (aref layerID stackPos)))) (set! layer (car (gimp-image-get-active-layer image))) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (gimp-image-add-layer image copyLayer 0) (set! numLayers (- numLayers 1)) (set! stackPos (+ stackPos 1)) ) ) ) (set! width (car (gimp-image-width image))) (set! height (car (gimp-image-height image))) (gimp-image-crop image width height 0 0) (gimp-selection-load origSelect) (gimp-image-remove-channel image origSelect) (gimp-displays-flush) (gimp-undo-push-group-end image) (gimp-context-pop) ) ) (script-fu-register "fp-script-fu-move-layer-anim" "/Filters/Animation/Animators/Move Layer..." "Move layers or masks based on number of selected frames or specified coordinates." "Art Wade" "Art Wade" "January 25, 2010" "*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT "Number of Frames" '(5 5 5000 1 10 0 1) SF-OPTION "Move Layer Options (Options 1-8 layers stay in place, but allows wrap around)" '("1. Up" "2. Down" "3. Left" "4. Right" "5. Up and Left" "6. Up and Right" "7. Down and Left" "8. Down and Right" "9. Using start/end coordinates" "10. Using current layer location as starting point \n (Requires ending x/y coordinate)" "11. Using Active Path") SF-TOGGLE "Ping-Pong Mode" FALSE SF-TOGGLE "Ignore Background Layer During Ping-Pong Mode" TRUE SF-OPTION "Layer Handle for Placement (Works only with Move Layer Options 9 - 11)" '("Top left" "Top Middle" "Top Right" "Middle Left" "Center" "Middle Right" "Bottom Left" "Bottom Middle" "Bottom Right") SF-ADJUSTMENT "Starting X Coordinate" '(0 -10000 10000 10 1 0 1) SF-ADJUSTMENT "Starting Y Coordinate" '(0 -10000 10000 10 1 0 1) SF-ADJUSTMENT "Ending X Coordinate" '(0 -10000 10000 10 1 0 1) SF-ADJUSTMENT "Ending Y Coordinate" '(0 -10000 10000 10 1 0 1) SF-TOGGLE "Add Path Created During Options 8 and 9" FALSE SF-OPTION "Blend Mode for Layers" '("Normal" ; 0 "Dissolve" ; 1 "Multiply" ; 3 "Divide" ; 15 "Screen" ; 4 "Overlay" ; 5 "Dodge" ; 16 "Burn" ; 17 "Hard light" ; 18 "Softlight Mode" ; 19 "Grain extract" ; 20 "Grain merge" ; 21 "Difference" ; 6 "Addition" ; 7 "Substract" ; 8 "Darken only" ; 9 "Lighten only" ; 10 "Hue" ; 11 "Saturation" ; 12 "Color" ; 13 "Value" ; 14 ) SF-ADJUSTMENT "Opacity for Layers" '(100.0 0.0 100.0 10 10 1 0) SF-OPTION "Layer Offset Fill Type (Works only with Options 1-7)" '("Wrap around image" "Fill empty space with current background color" "Fill empty space with transparency") )