; Define the function: (define (script-fu-tgif dir rootFirst rootLast bgcolour threshold) (set! n rootFirst) ; open the first file as the baseimage (set! fname (string-append dir "/sshot" (number->string n 10) ".jpg")) (set! baseimage (car (gimp-file-load 1 fname fname))) ; duplicate it to the newimage (set! newimage (car (gimp-channel-ops-duplicate baseimage))) ; get rid of the baseimage (gimp-image-delete baseimage) ; get some details of the image - assume the same for subsequent images (set! newlayer (car (gimp-image-get-active-layer newimage))) (set! width (car (gimp-drawable-width newlayer))) (set! height (car (gimp-drawable-width newlayer))) (gimp-layer-add-alpha newlayer) (set! type (car (gimp-drawable-type newlayer))) ; rename the first layer (gimp-layer-set-name newlayer (string-append "frame " (number->string n 10))) ; clear background colour ; old gimp 1.0 ; (gimp-by-color-select newimage newlayer bgcolour threshold REPLACE FALSE ; FALSE 10 FALSE) ; ; (gimp-edit-clear newimage newlayer) ; ; new gimp 1.1 (gimp-by-color-select newlayer bgcolour threshold REPLACE FALSE FALSE 10 FALSE) (gimp-edit-clear newlayer) ;undo the selection (gimp-selection-none newimage) ; loop over subsequent images (set! n (+ n 1)) (while (<= n rootLast) ;load the next image (set! fname (string-append dir "/sshot" (number->string n 10) ".jpg")) (set! image (car (gimp-file-load 1 fname fname))) ;old gimp 1.0 ; (gimp-image-disable-undo image) ;new gimp 1.1 (gimp-image-undo-disable image) ;get the layer to copy (set! layer-to-copy (car (gimp-image-get-active-layer image))) ;create space for the newlayer in newimage (set! newlayer (car (gimp-layer-new newimage width height type "crap" 100 NORMAL))) (gimp-layer-add-alpha newlayer) ; clear the newlayer of the newimage (this ensures the origin is set to ; the top left corner) (gimp-selection-all newimage newlayer) ; old gimp 1.0 ; (gimp-edit-clear newimage newlayer) ; new gimp 1.1 (gimp-edit-clear newlayer) (gimp-selection-none newimage) ;have to do the copy with edit-copy and edit-paste (gimp-selection-all image) ; old gimp 1.0 ; (gimp-edit-copy image layer-to-copy) ; new gimp 1.1 (gimp-edit-copy layer-to-copy) (gimp-selection-none image) ; old gimp 1.0 ; (set! float (car (gimp-edit-paste newimage newlayer FALSE))) ; new gimp 1.1 (set! float (car (gimp-edit-paste newlayer FALSE))) (gimp-floating-sel-to-layer float) ;reset name (gimp-layer-set-name float (string-append "frame " (number->string n 10))) ; clear background colour ; old gimp 1.0 ; (gimp-by-color-select newimage float bgcolour threshold REPLACE FALSE ; FALSE 10 FALSE) ; ; (gimp-edit-clear newimage float) ; new gimp 1.1 ; new gimp 1.1 (gimp-by-color-select float bgcolour threshold REPLACE FALSE FALSE 10 FALSE) (gimp-edit-clear float) ;undo the selection (gimp-selection-none newimage) ; old gimp 1.0 ; (gimp-image-enable-undo image) ; new gimp 1.1 (gimp-image-undo-enable image) ;get rid of copied layer and image (gimp-image-remove-layer newimage newlayer) (gimp-image-delete image) (set! n (+ n 1)) ;end of while ) (gimp-image-clean-all newimage) (gimp-display-new newimage) ) ; Register the function with the GIMP: ; SF-VALUE "Directory containing gifs" "\"./\"" (script-fu-register "script-fu-tgif" "/Xtns/Script-Fu/APB/tgif" "Animates a bunch of sequentially numbered jpg files" "Andy Beardmore" "Andy Beardmore" "15 Jan 2000" "RGB RGBA" SF-VALUE "Directory containing jpgs" "\"/home/apb\"" SF-VALUE "First jpg:" "1" SF-VALUE "Last jpg:" "10" SF-COLOR "Background colour to select:" '(0 0 255) SF-VALUE "Select threshold:" "120" )