Mobile app version of vmapp.org
Login or Join
Sent7350415

: In gimp : how to save the different layers of a design in separate files/images? I wonder if there's a way in gimp to make the different layers of a design into separate image files without

@Sent7350415

Posted in: #Gimp #Layers

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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent7350415

3 Comments

Sorted by latest first Latest Oldest Best

 

@Pierce403

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)

10% popularity Vote Up Vote Down


 

@Kaufman565

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")

10% popularity Vote Up Vote Down


 

@LarsenBagley460

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

the link is given below check this and read this carefully..
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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme