Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues building channels from EXRs #21

Open
jwin84 opened this issue Jan 15, 2019 · 1 comment
Open

Having issues building channels from EXRs #21

jwin84 opened this issue Jan 15, 2019 · 1 comment

Comments

@jwin84
Copy link

jwin84 commented Jan 15, 2019

  • 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
@tappi287
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants