Nofew

Gimp move layer script

Oct 19th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 10.00 KB | None | 0 0
  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ;
  19. ;
  20. ; Creates animations from single layers.  A script version of the "Move Layer" Option
  21. ; found within the GIMP Animation Plugin.
  22. ;
  23. ; The script can be found on an open image in GIMP 2.6 under: Filters > Animation > Move Layer...
  24. ;
  25.  
  26.  
  27.  
  28. ; Define the Function
  29.  
  30. (define (fp-script-fu-move-layer-anim   image        
  31.                 layer
  32.                 frames
  33.                 direction
  34.                 pingPong
  35.                 pingCopy
  36.                 layerHandle
  37.                 startX
  38.                 startY
  39.                 endX
  40.                 endY
  41.                 addPath
  42.                 blendMode
  43.                 opacity
  44.                 fillOption
  45.                 )
  46.  
  47. ; Declare the Variables
  48.  
  49.     (let* (
  50.                 (height 0)
  51.             (width 0)
  52.             (copyLayer 0)
  53.             (origSelect 0)
  54.             (wrap 0)
  55.             (x-dir
  56.                 (cond
  57.                 (( equal? direction 0 ) 0)     
  58.                 (( equal? direction 1 ) 0)
  59.                 (( equal? direction 2 ) -1)    
  60.                 (( equal? direction 3 ) 1)     
  61.                 (( equal? direction 4 ) -1)    
  62.                 (( equal? direction 5 ) 1)     
  63.                 (( equal? direction 6 ) -1)    
  64.                 (( equal? direction 7 ) 1)
  65.                 )
  66.             )      
  67.             (y-dir
  68.                 (cond
  69.                 (( equal? direction 0 ) -1)    
  70.                 (( equal? direction 1 ) 1)
  71.                 (( equal? direction 2 ) 0)     
  72.                 (( equal? direction 3 ) 0)     
  73.                 (( equal? direction 4 ) -1)    
  74.                 (( equal? direction 5 ) -1)    
  75.                 (( equal? direction 6 ) 1)     
  76.                 (( equal? direction 7 ) 1)
  77.                 )
  78.             )      
  79.             (step-x 0)
  80.             (step-y 0)
  81.             (offset-x 0)
  82.             (offset-y 0)
  83.             (mode-lut '#(0 1 3 15 4 5 16 17 18 19 20 21 6 7 8 9 10 11 12 13 14))
  84.             (vectors 0)
  85.             (pathLength 0)
  86.             (dist 0)
  87.             (distInc 0)
  88.             (points (cons-array 12 'double))
  89.             (numLayers 0)
  90.             (layerID 0)
  91.             (stackPos 1)
  92.             (fillColor 0)
  93.             )
  94.  
  95. (gimp-context-push)
  96. (gimp-undo-push-group-start image)
  97.  
  98. (set! origSelect (car (gimp-selection-save image)))
  99. (gimp-selection-none image)
  100.  
  101. (set! width (car (gimp-drawable-width layer)))
  102. (set! height (car (gimp-drawable-height layer)))
  103.  
  104. (gimp-layer-add-alpha layer)
  105. (gimp-layer-set-mode layer (vector-ref mode-lut blendMode))
  106. (gimp-layer-set-opacity layer opacity)
  107.  
  108. (if (= pingPong TRUE)
  109.     (set! frames (ceiling (/ frames 2)))
  110. )
  111.  
  112. (if (= direction 9)
  113.     (begin 
  114.     (set! startX (car (gimp-drawable-offsets layer)))
  115.     (set! startY (cadr (gimp-drawable-offsets layer)))
  116.     )
  117. )
  118.  
  119. (if (= direction 10)
  120.     (set! vectors (car (gimp-image-get-active-vectors image)))
  121. )  
  122.  
  123.  
  124. (if (> direction 7)
  125.  
  126.     (begin
  127.  
  128.     (if (or (= direction 8)(= direction 9))
  129.         (begin
  130.         (set! vectors (car (gimp-vectors-new image "New Path")))
  131.         (aset points 0 startX) 
  132.         (aset points 1 startY)
  133.         (aset points 2 startX)
  134.         (aset points 3 startY)
  135.         (aset points 4 startX)
  136.         (aset points 5 startY)
  137.         (aset points 6 endX)
  138.         (aset points 7 endY)
  139.         (aset points 8 endX)
  140.         (aset points 9 endY)
  141.         (aset points 10 endX)
  142.         (aset points 11 endY)  
  143.         (gimp-vectors-stroke-new-from-points vectors 0 12 points FALSE)
  144.         )
  145.     )
  146.  
  147.  
  148.  
  149.    
  150.     (set! pathLength (trunc (car (gimp-vectors-stroke-get-length vectors 1 1))))
  151.     (set! distInc (/ pathLength (- frames 1)))
  152.  
  153. (if (and (or (= direction 8)(= direction 9)) (= addPath TRUE))
  154. (gimp-image-add-vectors image vectors -1)
  155. )
  156.  
  157.         (while (>= frames 0)
  158.  
  159.             (set! offset-x (car (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1)))
  160.             (set! offset-y (cadr (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1)))
  161.             (set! copyLayer (car (gimp-layer-copy layer TRUE)))
  162.            
  163.             (if (> frames 0)
  164.             (gimp-image-add-layer image copyLayer -1)
  165.             )  
  166.        
  167.  
  168. (cond
  169.  
  170.   (     (= layerHandle 1) ; top middle
  171.     (set! offset-x (- offset-x (/ width 2)))
  172.   )
  173.   (     (= layerHandle 2) ; top right
  174.     (set! offset-x (- offset-x width))
  175.   )
  176.   (     (= layerHandle 3) ; middle left
  177.     (set! offset-y (- offset-y (/ height 2)))
  178.   )
  179.   (     (= layerHandle 4) ; center
  180.     (set! offset-x (- offset-x (/ width 2)))
  181.     (set! offset-y (- offset-y (/ height 2)))
  182.   )
  183.   (     (= layerHandle 5) ; middle right
  184.     (set! offset-x (- offset-x width))
  185.     (set! offset-y (- offset-y (/ height 2)))
  186.   )
  187.   (     (= layerHandle 6) ; bottom left
  188.     (set! offset-y (- offset-y height))
  189.   )
  190.   (     (= layerHandle 7) ; bottom middle
  191.     (set! offset-x (- offset-x (/ width 2)))
  192.     (set! offset-y (- offset-y height))
  193.   )
  194.   (     (= layerHandle 8) ; bottom right
  195.     (set! offset-x (- offset-x width))
  196.     (set! offset-y (- offset-y height))
  197.   )
  198.  
  199. )
  200.  
  201.         (gimp-layer-set-offsets copyLayer offset-x offset-y)
  202.         (if (> frames 0)
  203.         (gimp-layer-resize-to-image-size copyLayer)
  204.         )
  205.         (set! frames (- frames 1))
  206.         (set! dist (+ dist distInc))
  207.         ); while closure
  208.  
  209.     ;(gimp-image-remove-layer image layer)
  210.  
  211.     ); begin closure
  212.  
  213.  
  214.     (begin
  215.     (set! step-x (* x-dir (/ width frames)))
  216.     (set! step-y (* y-dir (/ height frames)))
  217.     (set! offset-x step-x)
  218.     (set! offset-y step-y)
  219.     (set! frames (- frames 1))
  220.  
  221.  
  222.                 (while (>= frames 1)
  223.                 (set! copyLayer (car (gimp-layer-copy layer TRUE)))
  224.                 (gimp-image-add-layer image copyLayer -1)
  225.                
  226.                 (if (= fillOption 0)
  227.                     (begin
  228.                     (set! wrap TRUE)
  229.                     (set! fillColor 1)
  230.                     )
  231.                 )
  232.                
  233.                 (if (= fillOption 1)
  234.                     (begin
  235.                     (set! wrap FALSE)
  236.                     (set! fillColor 0)
  237.                     )
  238.                 )
  239.  
  240.                 (if (= fillOption 2)
  241.                     (begin
  242.                     (set! wrap FALSE)
  243.                     (set! fillColor 1)
  244.                     )
  245.                 )
  246.  
  247.                 (gimp-drawable-offset copyLayer wrap fillColor offset-x offset-y)
  248.  
  249.                 (set! offset-x (+ offset-x step-x))
  250.                 (set! offset-y (+ offset-y step-y))
  251.  
  252.                 (set! frames (- frames 1))
  253.  
  254.                 ); while closure
  255.  
  256.     ); begin closure direction < 7
  257.  
  258. ); if direction > 7 closure
  259.  
  260.  
  261. (if (= pingPong TRUE)
  262.  
  263.     (begin
  264.  
  265.         (if (= pingCopy TRUE)
  266.             (set! numLayers (- (car (gimp-image-get-layers image)) 1))
  267.             (set! numLayers (car (gimp-image-get-layers image)))
  268.         )
  269.  
  270.     (set! layerID (cadr (gimp-image-get-layers image)))
  271.  
  272.     (while (> numLayers 2)
  273.         (set! layer (car (gimp-image-set-active-layer image (aref layerID stackPos))))
  274.         (set! layer (car (gimp-image-get-active-layer image)))
  275.         (set! copyLayer (car (gimp-layer-copy layer TRUE)))
  276.         (gimp-image-add-layer image copyLayer 0)
  277.         (set! numLayers (- numLayers 1))
  278.         (set! stackPos (+ stackPos 1))
  279.     )
  280.     )
  281. )
  282.        
  283. (set! width (car (gimp-image-width image)))
  284. (set! height (car (gimp-image-height image)))
  285.  
  286. (gimp-image-crop image width height 0 0)
  287.  
  288. (gimp-selection-load origSelect)
  289. (gimp-image-remove-channel image origSelect)    
  290.  
  291. (gimp-displays-flush)
  292. (gimp-undo-push-group-end image)
  293. (gimp-context-pop)
  294.  
  295.  
  296.  
  297.   )
  298. )
  299.  
  300. (script-fu-register "fp-script-fu-move-layer-anim"
  301.   "<Image>/Filters/Animation/Animators/Move Layer..."
  302.   "Move layers or masks based on number of selected frames or specified coordinates."
  303.   "Art Wade"
  304.   "Art Wade"
  305.   "January 25, 2010"
  306.   "*"
  307.   SF-IMAGE          "Image" 0
  308.   SF-DRAWABLE       "Drawable" 0
  309.   SF-ADJUSTMENT "Number of Frames" '(5 5 5000 1 10 0 1)
  310.   SF-OPTION "Move Layer Options (Options 1-8 layers stay in place, but allows wrap around)" '("1. Up"
  311.                                    "2. Down"
  312.                            "3. Left"
  313.                                    "4. Right"
  314.                                    "5. Up and Left"
  315.                                    "6. Up and Right"
  316.                                    "7. Down and Left"
  317.                                    "8. Down and Right"
  318.                         "9. Using start/end coordinates"
  319.                         "10. Using current layer location as starting point \n      (Requires ending x/y coordinate)"
  320.                         "11. Using Active Path")
  321.   SF-TOGGLE     "Ping-Pong Mode"    FALSE
  322.   SF-TOGGLE     "Ignore Background Layer During Ping-Pong Mode" TRUE
  323.   SF-OPTION     "Layer Handle for Placement (Works only with Move Layer Options 9 - 11)" '("Top left"
  324.                                 "Top Middle"
  325.                                 "Top Right"
  326.                                 "Middle Left"
  327.                                 "Center"
  328.                                 "Middle Right"
  329.                                 "Bottom Left"
  330.                                 "Bottom Middle"
  331.                                 "Bottom Right")
  332.   SF-ADJUSTMENT "Starting X Coordinate" '(0 -10000 10000 10 1 0 1)  
  333.   SF-ADJUSTMENT "Starting Y Coordinate" '(0 -10000 10000 10 1 0 1)  
  334.   SF-ADJUSTMENT "Ending X Coordinate" '(0 -10000 10000 10 1 0 1)  
  335.   SF-ADJUSTMENT "Ending Y Coordinate" '(0 -10000 10000 10 1 0 1)  
  336.   SF-TOGGLE     "Add Path Created During Options 8 and 9"   FALSE
  337.   SF-OPTION     "Blend Mode for Layers" '("Normal"  ; 0
  338.                            "Dissolve"   ; 1
  339.                                    "Multiply"   ; 3
  340.                                    "Divide"     ; 15
  341.                                    "Screen"     ; 4
  342.                                    "Overlay"    ; 5
  343.                                    "Dodge"      ; 16
  344.                                    "Burn"       ; 17
  345.                                    "Hard light" ; 18
  346.                                    "Softlight Mode"     ; 19
  347.                          "Grain extract" ; 20
  348.                                    "Grain merge" ; 21
  349.                                    "Difference" ; 6
  350.                                    "Addition"   ; 7
  351.                                    "Substract"  ; 8
  352.                                    "Darken only" ; 9
  353.                                    "Lighten only" ; 10
  354.                                    "Hue" ; 11
  355.                                    "Saturation" ; 12
  356.                                    "Color" ; 13
  357.                                    "Value" ; 14
  358.                                    )    
  359.   SF-ADJUSTMENT     "Opacity for Layers" '(100.0 0.0 100.0 10 10 1 0)
  360.   SF-OPTION     "Layer Offset Fill Type (Works only with Options 1-7)" '("Wrap around image"
  361.                                 "Fill empty space with current background color"
  362.                                 "Fill empty space with transparency")
  363. )
Advertisement