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

How do I save PSD which converted from nested_layers WITHOUT any raster masks? #30

Open
ppooiiuuyh opened this issue Aug 13, 2020 · 1 comment

Comments

@ppooiiuuyh
Copy link

Description

When saving a psd converted from nested layers created from scratch using a numpy image, unexpected raster masks was created with it. Is there any way to save a psd file without any raster masks?

What I Did

Initially, the raster mask value was set to 0, so the image was not visible.

image

I could solve this by changing the parameter value of the layer mask class below. But still I couldn't find a way to remove the raster masks.

# pytoshop -> layers -> LayerMask
class LayerMask(object):
    """
    Layer mask / adjustment layer data.
    """
    def __init__(self,
                 top=0,                                      # type: int
                 left=0,                                     # type: int
                 bottom=0,                                   # type: int
                 right=0,                                    # type: int
                 default_color=True,#<- False            # type: bool
                 position_relative_to_layer=False,           # type: bool
                 layer_mask_disabled=True, #<- False    # type: bool
                 invert_layer_mask_when_blending=False,      # type: bool

image

Here is my entire code,

import pytoshop.user.nested_layers
import pytoshop.enums
import os
import cv2

def save_decomposed_psd(dst_path, s=None,su=None):
    def gen_layer(img, name):
        if img.shape[-1] ==3 :
            img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)

        layer = pytoshop.user.nested_layers.Image(name=name, group_id=0, top=0, left=0, bottom=img.shape[0], right=img.shape[1], channels=None, metadata=None, layer_color=0, color_mode=3)
        ca = pytoshop.layers.ChannelImageData(image=img[...,-1])
        cr = pytoshop.layers.ChannelImageData(image=img[...,2])
        cg = pytoshop.layers.ChannelImageData(image=img[...,1])
        cb = pytoshop.layers.ChannelImageData(image=img[...,0])
        layer.channels = {-1:ca, 0:cr, 1:cg, 2:cb}
        return layer

    def gen_group(layers, name):
        group = pytoshop.user.nested_layers.Group(name=name, group_id=0, layers=layers)
        return group

    psd_nl = [gen_group([gen_layer(s,"s"), gen_layer(su,"su")], "gs")]

    psd = pytoshop.user.nested_layers.nested_layers_to_psd(psd_nl, color_mode=3)
    with open(dst_path, 'wb') as fd:
        psd.write(fd)


if __name__ == "__main__":
    root = "/root/results/psd_tools_practice"
    s = cv2.imread(os.path.join(root,"a.png"), cv2.IMREAD_UNCHANGED)
    su = cv2.imread(os.path.join(root,"b.png"), cv2.IMREAD_UNCHANGED)

    dst = os.path.join(root,"decoposed_psd")
    save_decomposed_psd(dst,s)
@2lives
Copy link

2lives commented Feb 24, 2023

Yo, open the file in actual photoshop ;]

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