Gif Movie Modifier Gimp Script
Sometimes it may be desirable to be able to modify either the speed
or the size of an animated gif file to see more detail. A simple gimp plug
in script can modify the gif image above to what shown below.
Normally it is more desirable to scale the gif image smaller to save on image
When installed, the script's menu will be found under the Filter/Animation
Select a gif file, and the output file will be renamed and placed in the same
When the image is scaled by 30%, so will it's file size. The timing corresponds
to the wait period in milliseconds between images.
Sometimes things like this need to be done to catch all the details of
what is happening. Gimp is open source software. This tends to install
some beauty into the way things get done. For instance, the full code to
this script is shown below. It's
code is here.
"Adjust Size and Speed of Gif Movie"
"Don Sauer email@example.com"
SF-FILENAME "SF-FILENAME" "/"
SF-ADJUSTMENT "Timing-ms" '(100 10 2000 50 10 1 0)
SF-ADJUSTMENT "PercentScale-%" '(100 30 600 10 1 1 0)
(script-fu-menu-register "AdjustGifMovie" "<Image>/Filters/Animation")
(define (AdjustGifMovie fpath timing scale)
(image (car (file-gif-load 1 fpath "giffile")))
;;======= first set up new image
(set! null (gimp-display-new image ))
(set! backlay (car (gimp-image-get-active-layer image)))
(set! null (gimp-drawable-set-name backlay "backlay"))
;;======= clean up a second image using animationunoptimize
(set! image2 (car (plug-in-animationunoptimize 1 image backlay)))
(set! backlay2 (car (gimp-image-get-active-layer image2)))
(set! null (gimp-display-new image2 ))
;;======= find out how many layers
(set! NumbLay (car (gimp-image-get-layers image2)))
;;======= all the layers need to be renamed using (replace)
(set! i 0 )
(while (< i NumbLay)
(set! null (gimp-drawable-set-name (vector-ref(car(cdr(gimp-image-get-layers image2)))i) "lay (replace)"))
(set! i (+ i 1))
;;======= get dimension of the image
(set! w (car (gimp-image-width image) ))
(set! h (car (gimp-image-height image) ))
;;======= scale second image
(set! null (gimp-image-scale image2 (* w ( / scale 100)) (* h ( / scale 100)) ))
;;======= create the file name
(set! fpath2 (string-append (substring fpath 0 (-(string-length fpath) 4) ) "_adj.gif" ))
;;======= save gif movie
(set! null (file-gif-save 1 image2 backlay2 fpath2 "giffile" 0 1 timing 0) )
When the code gets color coded, it is easier to see that the code has a
self documentation feature to it. To start off, all standard gimp functions will
be encoded in blue. The user function called "AdjustGifMovie" is shown in green.
The first standard function "script-fu-register" links the "AdjustGifMovie" name to the
dialog window parameters, which are listed in light blue.
The second standard function "script-fu-menu-register" links the "AdjustGifMovie" name to
a menu location.
The third standard function "define" links the "AdjustGifMovie" name to its input
parameter in light blue. In this case, variables are coded in red. The standard functions
shown in blue are named to say what they do. For instance "file-gif-load" will load
into the variable "image", the address of a gif image found from the file path "fpath".
This type of programing likes to first declare variable names, and then reset the
values to the name with a set! statement. While the processing of information is more like
reverse polish notation, the code does appear to self document itself as to what function
is changing what variable as defined by what input parameters.