Created
October 10, 2013 04:47
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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