Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Script-Fu, loading and saving a PNG loses alpha

Tags:

script-fu

I'm trying to write a script in GIMP that will load a PNG file and save it again with maximum compression (I also plan on adding other processing steps). The following script, however, seems to destroy alpha information:

(define (process-png pattern)
  (let* (
      (filelist (cadr (file-glob pattern 1)))
    )
    (while (not (null? filelist))
      (begin
        (catch ()
          (let* (
              (filename (car filelist))
              (image (car (file-png-load RUN-NONINTERACTIVE filename filename)))
            )
            (begin
              (file-png-save2 RUN-NONINTERACTIVE
                  image (car (gimp-image-get-active-drawable image))
                  filename filename
                  0 9 0 0 0 0 0 0 0)
              (gimp-image-delete image)
            )
          )
        )
        (set! filelist (cdr filelist))
      )
    )
  )
)

For instance, the translucent pixels in JQuery icons all seem to become completely transparent, making everything aliased.

How can this be fixed?

like image 715
Olathe Avatar asked Oct 21 '22 11:10

Olathe


1 Answers

The documentation of file-png-save2 says that the last parameter is for Preserve color of transparent pixels? which in your case is set to 0. Try to set this to 1 and it should just work fine.

like image 166
Ankur Avatar answered Oct 25 '22 19:10

Ankur