5

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?

Olathe
  • 1,885
  • 1
  • 15
  • 23

1 Answers1

3

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.

Ankur
  • 33,367
  • 2
  • 46
  • 72
  • The colors are being preserved just fine, but I tried that anyway, and it's still losing alpha information. You can see by trying it with the JQuery icons link in the original description. Open the original and processed files in Gimp, set the zoom to 800%, change to RGB mode, and add a red background layer. You'll be able to see translucent pixels in one but not the other. – Olathe Apr 28 '13 at 10:07