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

Some layers are disappeared and changed. #18

Open
Rockheung opened this issue Oct 9, 2018 · 0 comments
Open

Some layers are disappeared and changed. #18

Rockheung opened this issue Oct 9, 2018 · 0 comments

Comments

@Rockheung
Copy link

Rockheung commented Oct 9, 2018

  • psdwriter version: You mean pytoshop version? 1.2.0 and download directly from PyPI and installed manually.
  • Python version: 3.6.5
  • Operating System: 4.15.0-36-generic Ubuntu 18.04 LTS

Description

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

< 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.

  • hello
  • background copy
  • background (UNLOCKED)

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.

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

1 participant