Search code examples
pythonimagepython-imaging-librarylayerpsd

Python PSD layers?


I need to write a Python program for loading a PSD photoshop image, which has multiple layers and spit out png files (one for each layer). Can you do that in Python? I've tried PIL, but there doesn't seem to be any method for accessing layers. Help. PS. Writing my own PSD loader and png writer has shown to be way too slow.


Solution

  • Use Gimp-Python? http://www.gimp.org/docs/python/index.html

    You don't need Photoshop that way, and it should work on any platform that runs Gimp and Python. It's a large dependency, but a free one.

    For doing it in PIL:

    from PIL import Image, ImageSequence
    im = Image.open("spam.psd")
    layers = [frame.copy() for frame in ImageSequence.Iterator(im)]
    

    Edit: OK, found the solution: https://github.com/jerem/psdparse

    This will allow you to extract layers from a psd file with python without any non-python stuff.