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

Error in showing opacity level of PSD file through changing alpha channel #14

Open
geminthair opened this issue Aug 31, 2018 · 1 comment

Comments

@geminthair
Copy link

  • psdwriter version:
  • Python version: 3.7
  • Operating System: iOS

Description

I'm trying to merge two PNG file into a PSD file, but the result showed that it failed to show the opacity attributes. I don't know if I failed to find a correct module to run this operation, or that I had inputed wrong attributes. If it's the case that I found a wrong module, can someone please show me the original source code that directly addresses alpha channels?

What I Did

import pytoshop
from pytoshop.user import nested_layers
from pytoshop import enums
import numpy as np
from scipy import misc #read png
from PIL import Image
import numpy as np

img2 = misc.imread('2.png') 
#print(img2)
print('img2:',img2.shape) 
img2_t = np.transpose(img2, (2, 0, 1)) 
#print(img2_t)
print('img2_t:',img2_t.shape) 
#img2_t = np.transpose(img2_t, (1, 2, 0))
#misc.imsave('2_t.png',img2_t)

img4 = misc.imread('4.png') 
#print(img4)
print('img4:',img4.shape)
img4_t = np.transpose(img4, (2, 0, 1)) 
#print(img4_t)
print('img4_t:',img4_t.shape) 
#img4_t = np.transpose(img4_t, (1, 2, 0))
#misc.imsave('4_t.png',img4_t)





new_layer = pytoshop.user.nested_layers.Image(
    name='2.png', 
    visible=True, 
    opacity=255,
    group_id=0,
    blend_mode= b'norm', 
    top=250, 
    left=250,
    #bottom=1000,
    #right=1000, 
    # channels=(3,1000,1000), 
    channels=img2_t, 
    metadata=None, 
    layer_color=7, 
    color_mode=3
)

new_layer2 = pytoshop.user.nested_layers.Image(
    name='4.png', 
    visible=True, 
    opacity=255,
    group_id=0,
    blend_mode= b'norm', 
    top=0, 
    left=0,
    #bottom=500,
    #right=500, 
    # channels=(3,1000,1000), 
    channels=img4_t, 
    metadata=None, 
    layer_color=7, 
    color_mode=3
)
lays = [new_layer,new_layer2]
new_psd = pytoshop.user.nested_layers.nested_layers_to_psd(lays, color_mode=3, version=1, compression=1, depth=8, vector_mask=False)
print('new_layer:',new_layer)
#print(dir(new_layer))
print('_________________________________')
#print(new_layer.name)
#print('---new_psd:---',type(new_psd))
# # new_psd = pytoshop.user.nested_layers.nested_layers_to_psd(new_layer, color_mode=3)
with open('newfile.psd', 'wb') as fd: 
    new_psd.write(fd)

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
@magdev2022
Copy link

Did you solve this problem?

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