pytoshop icon indicating copy to clipboard operation
pytoshop copied to clipboard

Layer renaming behaves different when duplicated inside Photoshop

Open tappi287 opened this issue 6 years ago • 0 comments

  • psdwriter version: 1.2.1
  • Python version: 3.7.1
  • Operating System: OS X 10.11.6, Windows 10 17763

Description

Photoshop adds an copy suffix to layer names when duplicating layers. It doesn't do this when duplicating layers created with pytoshop. If a pytoshop layer is manually renamed in PS, the desired behaviour is restored.

I would like to help track the cause of this issue but have no idea where to start. The name itself seems to be created correctly as pascal string padded with 4 bytes. I can replicate this behaviour across versions CC 2014 to 2018 on OS X and Windows.

What I Did

""" Renaming issue when duplicating layers inside Photoshop example """
from pathlib import Path

import numpy as np
from pytoshop.enums import ColorChannel, ColorMode
from pytoshop.user import nested_layers

# Color channel types RGBA
CHANNEL_TYPES = [ColorChannel.red, ColorChannel.green, ColorChannel.blue, ColorChannel.transparency]

# Create Image Layer
layer = nested_layers.Image(name='Test_Layer', color_mode=ColorMode.rgb)

# Fill Layer with random image data
img_np = np.array(np.random.rand(256, 256, 3) * 255, dtype=np.uint8)

num_channels = range(0, img_np.shape[2])
for channel_type, channel_idx in zip(CHANNEL_TYPES, num_channels):
    layer.set_channel(channel_type, img_np[..., channel_idx])

# Create PsdFile from layer list
psd_obj = nested_layers.nested_layers_to_psd(layers=[layer], color_mode=ColorMode.rgb)

psd_file = Path(__file__).parent / 'test_psd.psd'

with open(psd_file, 'wb') as file:
    psd_obj.write(file)

tappi287 avatar Jan 15 '19 23:01 tappi287