pythonpsdopenimageio

Export PSD Layers to EXR in Python


I'm trying to write a program to read in a .psd file, split the layers into individual images (maintaining the original image's dimensions) and export them as EXR files.

I'm currently trying to use the OpenImageIo library to accomplish this but the documentation isn't particularly clear on how this can be achieved in python.

I've successfully managed to read the full .psd and export it to .exr, but nothing I've been trying seems to indicate that there is more than one layer (subimage) to interact with.

Is there:

  1. something obvious that I'm missing, or
  2. a better way to accomplish this?

Side note:

I have had some success using psd_tools2 but the images can't be exported as .exr nor are they the correct dimensions.


Solution

  • This is actually relatively straightforward, however there is one caveat in that it only seems to be supported for 8-bit psd files at the moment.

    import OpenImageIO as oiio
    
    sourcefile = '/path/to/sourcefile.psd'
    buf = oiio.ImageBuf(sourcefile)
    
    for layer in range(buf.nsubimages):
        buf.reset(sourcefile, subimage=layer)
        buf.write('/tmp/mylayer_{l}.exr'.format(l=layer))