Gimp Batch Mode Notes

Example1:
When booting my linux system I use a boot splash theme so I don't have to look at text for starting services.
With the splash theme, instead of text, png and animated mng images represent each starting service.
To create my custom splash theme, I modifyed an existing theme,
where the background color of each image needs to change to a transparent (alpha) color.
For png files, a simple gimp batch automation converts background to alpha..
For mng files, I need to disasseble the animation into png files with imagemagic batch process,
conver the background color to alpha with gimp batch automation,
and then assemble the png images back into an mng animation with gimp batch automation (still work in progress).

Summery of steps:
  1. Create a gimp script-fu named batch-set-alph, that takes a list of files and converts all black pixles to transparent alpha layer.
  2. Create a gimp script-fu named asseble_png_to_mng, that takes a png output file and a list of png files, and bundles int png's into an mng animation.
  3. Disasseble the mng into png files with imagemagic, and get details about the animation frame timing.
  4. Gimp batch mode to conver the background color to transparent alpha,
  5. Gimp batch mode to asseble the png's into a mng (not working yet).


Procedure:
  1. Unpack the mng
    convert bootmisc.mng  +repage  +adjoin  -coalesce script_k_%02d.png
    
  2. Discover the frame rate in the mng
    identify -verbose bootmisc.mng |egrep -i 'scene|delay'
    

      The output looks like this and tells us 100 milisecionds per frame:
        Delay: 100x100
        Scene: 0 of 4
        Delay: 100x100
        Scene: 1 of 4
        Delay: 100x100
        Scene: 2 of 4
        Delay: 100x100
        Scene: 3 of 4
      
  3. Create the file ~/.gimp-2.4/scripts/batch-set-alph.scm
    (define (batch-set-alph pattern )
        (let* ((filelist (cadr (file-glob pattern 1))))
            (while (not (null? filelist))
                (let*   (
                          (filename (car filelist))
                            (image (car (gimp-file-load 1        ;; 1=RUN-NONINTERACTIVE 
                                                        filename ;; file name
                                                        filename ;; raw-file name 
                                        )
                                   )
                            )
                            (drawable (car (gimp-image-get-active-layer image)))
                        )
                        (plug-in-colortoalpha  1        ;; 1=RUN-NONINTERACTIVE
                                               image    ;; image object name
                                               drawable ;; drawable layers
                                               '(0 0 0) ;; Color to make alpha (black)
                        )
                        (gimp-file-save 1        ;; 1=RUN-NONINTERACTIVE 
                                        image    ;; image object name
                                        drawable ;; Drawable layer to save
                                        filename ;; filename
                                        filename ;; raw-filename
                        )
                        (gimp-image-delete image))
                        (set! filelist (cdr filelist))
            )
        )
    )
    
  4. From the command line:
    gimp -i -b '(batch-set-alph "*.png" )' -b '(gimp-quit 0)'
  5. Create the file ~/.gimp-2.4/scripts/asseble_png_to_mng.scm
    ;;
    ;; Takes three files
    ;; First is opened,
    ;; Second is opened into first as a layer
    ;; Saves result as third (in animated mng format).
    ;;
    ;; SYNTAX: gimp -i -b '(asseble_png_to_mng "script_k_00.png" "script_k_01.png" "test.mng" )' -b '(gimp-quit 0)'
    ;;
    ;;
    (define ( asseble_png_to_mng input_file1 input_file2  out_file )
       (let* (
    
             ;;
             ;; Open input_file1 as image
             ;; Tested working.
             ;;
             (image (car (gimp-file-load 1 ;; RUN-NONINTERACTIVE
                                              input_file1 ;;
                                              input_file1 ;;
                               )
                          )
              )
             (drawable (car (gimp-image-get-active-layer image)))
             )
    
             ;;
             ;; Open input_file2 as a layer
             ;; Not working
             ;;
             (set! ( LogoLayer (car (gimp-file-load-layer     1          ;; RUN-NONINTERACTIVE
                                                         image       ;; destination image object
                                                         input_file2 ;; image to load in layer
                                   )
                           )
                   )
             )
             ;;
             ;; Add the layer to the image?
             ;; Not working
             ;;
             (gimp-image-add-layer   image        ;; The image
                                     LogoLayer  ;; The layer
                                     0            ;; The position
             )
    
             ;;
             ;; Now save the file as an mng
             ;; Tested, Working
             ;;
             (file-mng-save     1     ;; Interactive, non-interactive
                             image    ;; Input image
                             drawable ;; Drawable to save
                             out_file ;; filename (The name of the file to save the image in)
                             out_file ;; raw-filename (The name of the file to save the image in)
                                 0    ;; interlacing
                                 0    ;; PNG deflate Compression Level
                                 0.75 ;; JPEG quality factor (0.00 - 1.00)
                                 0.00 ;; JPEG smoothing factor (0.00 - 1.00)
                                 0    ;; (ANIMATED MNG) Loop infinitely
                                 100  ;; (ANIMATED MNG) Default delay between frames in millisecond
                                 2    ;; (ANIMATED MNG) Default chunks type (0 = PNG + Delta PNG; 1 = JNG + Delta PNG; 2 = All PNG; 3 = All JNG)
                                 0    ;; (ANIMATED MNG) Default dispose type (0 = combine; 1 = replace)
                                 0    ;; Write bKGD (background color) chunk
                                 0    ;; Write gAMA (gamma) chunk
                                 0    ;; Write pHYs (image resolution) chunk
                                 0    ;; Write tIME (creation time) chunk
                                 )
    
             (gimp-image-delete image)
       )
    )
    
  6. From the command line:
    gimp -i -b '(asseble_png_to_mng first.png second.png output.mng )' -b '(gimp-quit 0)'