Hi,
I’m experiencing issues with effects in psd files that are missing when saving the psd as png. Here an example psd file where “PLACEHOLDER1” and “Layer 733” have effects that go missing. Hope there is a simple fix for this. I run this code:
try:
# Load the PSD file
print(f"Loading PSD file: {psd_local_path}")
load_opts = PsdLoadOptions()
load_opts.load_effects_resource = True # <-- Effekte laden & rendern
load_opts.allow_warp_repaint = True
with _load_psd_with_effects(psd_local_path) as img:
psd_image = cast(PsdImage, img)
_log_layer_effects(psd_image)
print(f"PSD file loaded with {len(psd_image.layers)} layers")
# Check if loaded file is a PSD file
if not isinstance(psd_image, PsdImage):
raise TypeError(f"The file is of type: {type(psd_image)} and not a valid PSD file.")
print(f"PSD file loaded with {len(psd_image.layers)} layers")
# (optional) prüfen, ob Effekte an den Smart-Objekt-Ebenen aktiv sind
for layer in psd_image.layers:
try:
bo = layer.blending_options
if bo is not None and not bo.are_effects_enabled:
bo.are_effects_enabled = True
except Exception:
pass
# Flag to check if at least one SmartObject was found
smart_object_found = False
# Iterate through all layers
for layer in psd_image.layers:
# Check if the layer is a SmartObjectLayer and if its name is in our list
if is_assignable(layer, SmartObjectLayer) and layer.display_name in layer_names_to_replace:
# Cast the layer to SmartObjectLayer
smart_object_layer = cast(SmartObjectLayer, layer)
print(f"Replacing content in SmartObject layer: {layer.display_name}")
# Replace the content of the SmartObject with ResolutionSetting
res_settings = ResolutionSetting(300.0, 300.0) # Set resolution to 300 DPI
smart_object_layer.replace_contents(temp_image_path, res_settings)
smart_object_layer.update_modified_content() # Update changes
print(f"Content replaced in layer: {layer.display_name}")
smart_object_found = True
if not smart_object_found:
raise ValueError("No SmartObject with the specified names found.")
# Save the edited PSD file as PNG
print(f"Saving edited PSD as PNG to: {output_png_path}")
png_options = PngOptions()
png_options.color_type = PngColorType.TRUECOLOR_WITH_ALPHA # Important for transparency
psd_image.save(output_png_path, png_options)
if not os.path.exists(output_png_path):
raise FileNotFoundError(f"The output PNG file was not created: {output_png_path}")
output_file_size = os.path.getsize(output_png_path)
print(f"Saved output PNG: {output_png_path}, size: {output_file_size} bytes")
Here the psd file: Unique Download Link | WeTransfer
Hope you can help. Best regards