Skip to content

Instantly share code, notes, and snippets.

@jfcamel
Created June 18, 2011 21:15
Show Gist options
  • Select an option

  • Save jfcamel/1033515 to your computer and use it in GitHub Desktop.

Select an option

Save jfcamel/1033515 to your computer and use it in GitHub Desktop.
a gimp plugin (python-fu)
# -*- coding: utf-8 -*-
from gimpfu import *
import os
import glob # unused
colorpalette = []
def decolorFiles(dirname, ext, suffix):
"""
Convert Non-Indexed Image to Indexed Image.
"""
topdir = os.walk(dirname)
if suffix.find(ext) < 0:
suffix = suffix + ext
while 1:
try:
pwd, dirs, files = next(topdir)
os.chdir(pwd)
for f in files:
if f.endswith(ext):
abspath = os.path.abspath(f)
filename = f.split(ext)[0]
new_filename = filename + suffix
new_filename_path = os.path.join( os.path.dirname(abspath),
new_filename)
img = pdb.gimp_file_load(abspath, "")
drawable = pdb.gimp_image_get_active_layer(img)
pdb.gimp_image_convert_indexed(img, NO_DITHER, MAKE_PALETTE, 255, False, True, "")
#pdb.gimp_image_convert_indexed(img, NO_DITHER, CUSTOM_PALETTE, 255, False, True, colorpalette)
pdb.gimp_file_save(img, drawable, new_filename_path, "")
except StopIteration, e:
break
register(
"indexDecolor_batch", # name of procedure
"convert to indexed png batch procedure",
# description of procedure
"", # information appending to pdb
"jf", # author
"", # lisence
"2011", # create date
"IndexDeColor", # name in menu
"", # image type of procedure
[(PF_DIRNAME, "directory", "root directory of images for process", ""),
(PF_STRING, "extension", "image type", ".png"),
(PF_STRING, "suffix", "processed image suffix", "_indexed.png")],
# argument definition
[], # return value definition
decolorFiles, # procedure
menu="<Toolbox>/Xtns/MySample",) # register into
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment