Search code examples
imageextractphotoshopgimppsd

How to extract images from a PSD file including images contained in a single layer


I don't have much knowledge of imaging tools but I need to extract images contained within the layers of a psd file. I tried using GIMP with a "save all layers" plugin but that is just saving the root layers so I am ending up with just two .pngs. I need every image in a separate file with the correct sizes.

The reason I need the files is that I have been asking to create an animation with CSS using the images. An example animations is at http://srv1.contobox.com/frontend/ads/preview.html?id=981

The psd document I am trying to extract is https://www.dropbox.com/sh/ud2eaesej08o0g3/AAAi-_pPHGESOFOBpA0uQfjta


Solution

  • The problem is that these files are structured with Layer Groups (I opened just one of them). While GIMP is supporting open the file, the "save all layers" plug-in you are using probably is not aware of layer groups.

    (BTW, GIMP unstable - the 2.9 development version is likely currently broken for opening PSDs - the image opens garbled there. It opens in gimp 2.8.10, though)

    It is possible to save all layers - including sublayers, as separate images with an interaction in the Python console. With you PSD being the only image open in GIMP, go to filters->python->console and type something along this:

    img = gimp.image_list()[0]  # retrieves a reference to the image
    
    folder = "/tmp/" # folder of you choice for saving the files
    counter = 0
    def save_recurse(item):
        global counter 
        if hasattr(item, "layers"):
            for layer in reversed(item.layers):
                save_recurse(layer)
        else:
            counter += 1
            name = folder + "layer_%03d.png" % counter
            pdb.gimp_file_save(img, item, name, name)
    
    
    save_recurse(img)
    

    (btw, I typed it here in a way you can just copy and paste the listing above in GIMP's Python console)