multisplit.scm 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
; multisplit: splits up a mavica multi (sprites in one layer) into layers
; so you make make from png/jpg sprite a gif animation
; put me in ~/.gimp-ver/scripts and find me script-fu>animators>MultiSplit

(define (script-fu-multisplit multimg
			      drawable
			      horizontal
			      vertical
			      delay)
 (let* (
        (width 0)
        (height 0)
	(img 0)
	(layerNum 0)
	(hpos 0)
	(vpos 0)
	(layer 0)
	(floatingLayer 0)
       )

  (set! width (/ (car (gimp-image-width multimg)) horizontal))
  (set! height (/ (car (gimp-image-height multimg)) vertical))
  (set! img (car (gimp-image-new width height RGB)))

  (set! vpos 0)
  (while (< vpos vertical)
    (set! hpos 0)
    (while (< hpos horizontal) 
      (set! layerNum (+ layerNum 1))
      (set! layer (car (gimp-layer-new img width height RGB
                   (string-append "Frame" delay "(replace)")
		   100 NORMAL)))

      (gimp-layer-add-alpha layer)
      (gimp-drawable-fill layer TRANSPARENT-FILL)
      (gimp-image-add-layer img layer -1)

      (gimp-rect-select multimg
        (* hpos width) (* vpos height)
	width height
	REPLACE FALSE 0)

      (gimp-edit-copy drawable)

      (gimp-selection-all img)

      (set! floatingLayer (car (gimp-edit-paste layer 0)))
      (gimp-floating-sel-anchor floatingLayer)

      (gimp-selection-none img)
      (gimp-selection-none multimg)
      
      (set! hpos (+ hpos 1))
    )
    (set! vpos (+ vpos 1))
  )

  (gimp-display-new img)
 )
)

(script-fu-register "script-fu-multisplit" 
		    "<Image>/Script-Fu/Animators/MultiSplit"
		    "Split an image into layers"
		    "Rick Miller (Rick.Miller@Linux.org)"
		    "Rick Miller"
		    "05/19/2000"
		    "RGB RGBA GRAY GRAYA"
		    SF-IMAGE "Image" 0
		    SF-DRAWABLE "Drawable" 0
		    SF-VALUE "Horizontal Slices" "3"
		    SF-VALUE "Vertical Slices" "3"
		    SF-VALUE "Default Delay" "\"250ms\"")