You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import pytoshop, os
import numpy as np
from PIL import Image
from pytoshop.user import nested_layers as nl
from pytoshop.enums import *
def img_stacker(psdfile, imgfile, layer_name = None, file_suffix='_stacked',
offset = (0,0)):
x, y = offset
PSD_FILE_NAME, PSD_EXT = os.path.splitext(psdfile)
if layer_name is None:
layer_name = os.path.splitext(imgfile)[0]
img = np.array(Image.open(imgfile))
img_channels = [img[...,0],
img[...,1],
img[...,2]]
with open(psdfile, 'rb') as fd:
psd = pytoshop.read(fd)
nested_stuff = nl.psd_to_nested_layers(psd)
new_layer = nl.Image(name = layer_name,
channels = img_channels,
top = y,
left = x)
nested_stuff.insert(0, new_layer)
nl.pprint_layers(nested_stuff)
psd_tunned = nl.nested_layers_to_psd(layers = nested_stuff,
color_mode = ColorMode.rgb)
SAVE_PSD_FILE_NAME = PSD_FILE_NAME + file_suffix
# Somehow, write method seems to use opened file above
with open(SAVE_PSD_FILE_NAME + PSD_EXT, 'wb') as fe:
psd_tunned.write(fe)
return SAVE_PSD_FILE_NAME + PSD_EXT
if __name__ == "__main__":
ouput_file = img_stacker('example.psd', 'hello.png', offset = (0,10))
print('PSD file saved at {}'.format(ouput_file))
What I Did
I've made some simple PSD file using photoshop CS6 which has locked backgroud layer and one pasted png image, and empty layer which has nothing(just typed Shift+Ctrl+N and Enter). On photoshop, those are looks like below.
layer 1
background copy
background (locked)
before nested_layers_to_psd(), pprint_layers() says that
Description
What I Did
I've made some simple PSD file using photoshop CS6 which has locked backgroud layer and one pasted png image, and empty layer which has nothing(just typed Shift+Ctrl+N and Enter). On photoshop, those are looks like below.
before
nested_layers_to_psd()
,pprint_layers()
says that< hello (10, 0, None, None) > - image layer just added
< Layer 1 (0, 0, 0, 0) > - totally empty layer, fully transparent.
< Background copy (50, 107, 290, 347) > - original psd has 240*240 png image on transparent layer
< Background (0, 0, 340, 454) >
layer tree on photoshop.
Working well then I expected, but these minor issues exist. one empty layer disappeared, and background layer unlocked.
Additionally, above stacked.psd's file size changed after saving using photoshop. There might be some un-written-part.
The text was updated successfully, but these errors were encountered: