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
size.
When installed, the script's menu will be found under the Filter/Animation
menu.
Select a gif file, and the output file will be renamed and placed in the same
directory.
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.
=====================AdjustGifMovie.scm=====================================
(script-fu-register "AdjustGifMovie"
"AdjustGifMovie"
"Adjust Size and Speed of Gif Movie"
"Don Sauer dsauersanjose@aol.com"
"public domain"
"3.8.12_11.12AM"
""
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)
(let* (
(image (car (file-gif-load 1 fpath "giffile")))
(backlay 0)
(null 0)
(fpath2 0)
(image2 0)
(backlay2 0)
(NumbLay 0)
(w 0)
(h 0)
(i 0)
)
;;======= 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.
3.8.12_10.56AM
dsauersanjose@aol.com
Don Sauer