Skip to content

Instantly share code, notes, and snippets.

@andmatand
Created October 10, 2013 04:47
Show Gist options
  • Save andmatand/6913177 to your computer and use it in GitHub Desktop.
Save andmatand/6913177 to your computer and use it in GitHub Desktop.
GIMP plugin to save layer info to a format used by Kitty Town engine
#!/usr/bin/env python
from gimpfu import *
def get_layer_fields(layer):
return [layer.name,
str(layer.offsets[0]),
str(layer.offsets[1]),
str(layer.width),
str(layer.height)]
def write_layers(layers, file, prefix=''):
for layer in layers:
# If this layer is actually a layer group
if hasattr(layer, 'layers'):
write_layers(layer.layers, file, layer.name + '-')
else:
fields = get_layer_fields(layer)
fields[0] = prefix + fields[0]
file.write(','.join(fields) + '\n')
# This is the function that will perform actual actions
def save_rects(image, layer, filename):
file = open(filename, 'w')
write_layers(image.layers, file)
file.close()
# Register the plugin in Gimp
register(
"save_rects",
"Save Kitty Town Rects",
"Saves layer info to a format used by Kitty Town",
"Andrew Anderson",
"Andrew Anderson",
"October 2013",
"<Image>/File/Export/Save Kitty Town Rects...",
"*",
[(PF_FILE, "filepath", "Output Filename", "~/out.rects")],
[],
save_rects)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment