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))



  • Thank you sir! I had GIMP installed for less than 30 minutes with the sole purpose of converting around 300+ pngs to gifs for easier use in tkinter for python (I didn't want to have a requirement for PIL). Your script made VERY short time of conversion.

    By Blogger orangeboy, at 7:13 AM  

  • Glad the script helped!

    By Blogger Matthew Royal, at 10:44 PM  

Post a Comment

<< Home