Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for professional graphic designers and non-designers trying to do their own graphic design. It's 100% free, no registration required.

I wonder if there's a way in gimp to make the different layers of a design into separate image files without having to save the image each time. I hope this is clear. I use layers also as variations on the theme and for my latest projects i d like to put all those variations individually in a new context.

share|improve this question
    
i guess you have to get a plugin for saving layers in separate file –  Jack Mar 28 '11 at 5:20
add comment

3 Answers

The link to the script in the post pointed by Pankaj was broken, so I wrote my own "save layers" script in Python. To use the script, save the following script to your plug-in directory (e.g. ~/.gimp-x.x/plug-ins/save_all_layers.py), and if on Linux/Mac give the script the execute permission bit (e.g. chmod +x ~/.gimp-x.x/plug-ins/save_all_layers.py), then restart GIMP.

#!/usr/bin/env python

from gimpfu import *
from os.path import join

def save_all_layers(image, __unused_drawable, directory, name_pattern):
    for layer in image.layers:
        filename = join(directory, name_pattern % layer.name)
        raw_filename = name_pattern % layer.name
        pdb.gimp_file_save(image, layer, filename, raw_filename)

register(
    "python_fu_save_all_layers",
    "Save all layers into separate files",
    "Save all layers into separate files",
    "Lie Ryan",
    "Lie Ryan",
    "2012",
    "<Image>/File/Save layers as images...",
    "*",
    [
        (PF_DIRNAME, "directory", "Directory to put the images on", "/"),
        (PF_STRING, "name_pattern", "Pattern for file name, %s will be replaced with layer name", "%s.png"),
    ],
    [],
    save_all_layers
)

main()

Now you can just go to File > Save layers as images to, well, save layers as images.

Alternatively, if you do not fancy restarting GIMP or if you do not want to install the plugin permanently, then copy-paste the following function into the Python-fu console:

def save_all_layers(image, directory, name_pattern):
    for layer in image.layers:
        filename = join(directory, name_pattern % layer.name)
        raw_filename = name_pattern % layer.name
        pdb.gimp_file_save(image, layer, filename, raw_filename)

and use it as such:

>>> # first, find the image object
>>> gimp.image_list()
[<gimp.Image 'Untitled'>, <gimp.Image 'slice_5.xcf'>]
>>> # I want to edit slice_5.xcf, so I select that image
>>> img = gimp.image_list()[1]
>>> # double check that you got the correct image
>>> img
<gimp.Image 'slice_5.xcf'>
>>> # and finally call the function, the %s will be replaced by layer names
>>> save_all_layers(img, "/path/to/save/directory/", "image_%s.png")
share|improve this answer
    
works perfectly well, thanks! exports EVERYTHING, including hidden layers and transparency. UPVOTED! :) –  tony gil May 3 '13 at 16:06
    
Works like magic, one catch though, you should name the file exactly as he said 'save_all_layers.py' or it wont work –  BlackDivine Jul 25 '13 at 19:31
add comment

Just as a small update to the great @Lie Ryan's answer. There can be problems with layers which names contain special characters (like '/'), so save_all_layers function could be adjusted to handle this (based on this SO answer).

from os.path import join
import string

valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)

def make_safe(s):
    return ''.join(c for c in s if c in valid_chars)

def save_all_layers(image, directory, name_pattern):
    for layer in image.layers:
        filename = join(directory, make_safe(name_pattern % layer.name))
        raw_filename = make_safe(name_pattern % layer.name)
        pdb.gimp_file_save(image, layer, filename, raw_filename)
share|improve this answer
add comment

wherever i know you have to install a script for doing the same :

the link is given below check this and read this carefully..

http://registry.gimp.org/node/15617

@ all i am a newbie to gimp so might be less knowledge :(

if i am wrong than please correct me

Thanks

share|improve this answer
    
Within that page is indeed a link to a script which is intended to save multiple layers separately. –  mgkrebbs Mar 30 '11 at 5:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.