You are here

Script-FU: retaining GIF transparency

I have created a script (my first) which changes the colour of an image without affecting saturation (eg. blue becomes red, but grey remains grey). It works ok, except that the input GIF images become all-opaque. I didn't see any specific options on how to save a transparent GIF image. Any help? My script is below.

(define (recolour pattern hue-offset)

  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))))
                                  (if (not (= RGB (car (gimp-image-base-type image))))
                                                                  (gimp-image-convert-rgb image))
                  (let*(
                        (drawable (car (gimp-image-get-active-drawable image)))
                        (red (car (gimp-layer-new image 2000 2000 0 "red" 100 11)))
                        (final (gimp-image-flatten image))
                )
             (gimp-image-insert-layer image red 0 -1)
             (gimp-context-set-foreground '(255 0 0))
             (gimp-drawable-fill red 0)
             (set! final (car (gimp-image-flatten image)))
             (gimp-image-convert-indexed image NO-DITHER MAKE-PALETTE 255 FALSE TRUE "")
             (gimp-file-save RUN-NONINTERACTIVE image final filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist))))))

I'm pretty sure it's gimp-image-flatten that removes transparency, not gimp-file-save (which can save transparency in GIFs very well indeed). In fact, the documentation for gimp-image-flatten says that "the resulting image is stripped of its alpha channel."

I would use gimp-image-merge-down to merge layers in your case.

Subscribe to Comments for "Script-FU: retaining GIF transparency"