I've a .xcf-file with 20+ layers that I use for making a sprite-file.
I'd like to save all these layers to separate files with only the content and size of each layer.
I found this script for gimp: https://github.com/jiilee/gimp
Unfortunately that script creates files with the full size of the image and not the size of each layer.
To give an example: An image with that is 700px wide and 400px high. A layer is placed at x: 100px, y: 29px with width: 72px, height: 21px; The script I found makes a file that is 700px x 400px and not as I need 72px x 21px.
Is it possible to do this automatically?
Yes, but I'd recommend the use of Python as a scripting language in this case, rather than script-fu. For something like this, you would not even need a plug-in, you can just type something like the following on filters->python-fu->console
>>> img = gimp.image_list()[0]
>>> img.layers[0].name
'C'
>>> folder = "/tmp/"
>>> for layer in img.layers:
... name = folder + layer.name + ".png"
... pdb.gimp_file_save(img, layer, name, name)
...
>>>
Done! This snippet assumes a single image open in GIMP (it takes the last open
image in the list by default with the [0]
.)
The call to export an image takes in a drawable (which can be a layer, a mask, or other item) as input, and saves the file guessing the type by the filename extension with the default parameters.
And, of course, you can improve on it by creating a more elaborate naming scheme for the files, and so on. To make this core into an automated working python-fu plug-in, you just have to put it inside a function, in a .py file in your personal plug-in directory. (if on Unix/Mac OS/Linux you have to set it as executable as well) - and make calls to the register and main functions of GIMP-fu, in the same file - pick an example for here, http://www.ibm.com/developerworks/opensource/library/os-autogimp/ on how to arrange the file and make these calls. (You can go straight to listing 6).