Matthew's Big Blog of Adventure!

Monday, September 13

Converting PNG to GIF with Gimp's Script-fu

After wrestling for an hour with The GNU Image Manipulation Program's Script-fu system, and Googling aimlessly for an existing png2gif conversion script, I finally managed to cobble one together.

To run the script, right-click anywhere on an image in the Gimp to get the context menu. Then, Filters -> Script-Fu -> Console. Paste this script in with the path to the directory of files you want to convert:

(let* ((filelist (cadr (file-glob "C:\\directory\\*.png" 1))))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
(gimp-convert-indexed image 0 0 128 0 1 "")
(gimp-file-save 1 image drawable (string-append filename ".gif") (string-append filename ".gif"))
(set! filelist (cdr filelist))