mdboom/pytoshop

Having issues building channels from EXRs

jwin84 opened this issue · 1 comments

  • psdwriter version: 1.2.1
  • Python version: 3.6
  • Operating System: windows

Description

Hey, I'm trying to open a blank Photoshop doc and add layers to it that have image data from EXR's. So my main question is really, can pytoshop support EXR's as channel data. Thanks for any clarity you can provide, I know this is more of a broad support question.

What I Did

I'm creating a list of numpy arrays, where every array is a channel of the EXR. Them I'm outputting nested layers to PSD's

CODE:

    # get the path to the EXR
    exrPath = os.path.join(exrDirPath, exr)
    print('this is the current exr path: ', exrPath)

    # open the EXR 
    exrImg = OpenEXR.InputFile(exrPath)

    # --------------------------------
    # convert exr to pixel data
    rChan = exrImg.channel('R', FLOAT)
    gChan = exrImg.channel('G', FLOAT)
    bChan = exrImg.channel('B', FLOAT)

    rChanDefArray = array.array('f', rChan)
    gChanDefArray = array.array('f', gChan)
    bChanDefArray = array.array('f', bChan)


    rChanNumArray = numpy.array(rChanDefArray, dtype=numpy.float)
    gChanNumArray = numpy.array(gChanDefArray, dtype=numpy.float)
    bChanNumArray = numpy.array(bChanDefArray, dtype=numpy.float)

    channels = [rChanNumArray, gChanNumArray, bChanNumArray]

    layer = pytoshop.user.nested_layers.Image(name=exr.replace(".exr", ""), visible=True, 
                                   opacity=255, group_id=0,
                                   blend_mode=enums.BlendMode.normal, top=0,
                                   left=0, channels=channels,
                                   metadata=None, layer_color=0, color_mode=None)

    output = nested_layers.nested_layers_to_psd(layer, color_mode=3, size=(1024,1024))

    with open(psdPath, 'wb') as fd:
         output.write(fd)

It's failing at the 'output = nested_layers.nested_layers_to_psd(layer, color_mode=3, size=(1024,1024))' line...

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pytoshop\user\nested_layers.py", line 829, in nested_layers_to_psd
    _update_sizes(layers)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pytoshop\user\nested_layers.py", line 753, in _update_sizes
    width = channel.shape[1]
IndexError: tuple index out of range

Hi, the pytoshop.enums.ColorDepth says: Color depth (bits-per-pixel-per-channel). Supported values are 1, 8, 16, and 32. So this should be supported.

The index error indicates that your array has the wrong dimensions. The shape attribute of your channel should be a tuple reflecting the array dimension. In this case the shape should be tuple(1024, 1024)

Would you mind pointing me to the OpenExr libary and Windows binary you have used? I'd also like to support this and think I could help with a solution.

Sorry, I know this is not a dicussion board.