Aspose.PSD .net for python issues with missing effects

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

@caseai

It sounds like you’re encountering issues with missing effects when saving PSD files as PNGs using Aspose.PSD. Here’s a structured approach to troubleshoot and resolve the issue:

Cause: The missing effects in the PNG output may stem from incorrect loading of effects, disabled blending options, or issues with Smart Object layers.

Solution:

  1. Ensure Effects are Loaded: Confirm that load_opts.load_effects_resource = True is set correctly when loading the PSD file.

  2. Check Layer Effects: After loading the PSD, iterate through the layers to ensure that blending options are enabled. Check if layer.blending_options is not null and set bo.are_effects_enabled = True if necessary.

  3. Update Smart Object Layers: If you are replacing contents in Smart Object layers, ensure the replacement is done correctly. After replacing the content, call smart_object_layer.update_modified_content() to apply the changes.

  4. Save Options: When saving the image as PNG, ensure you are using the correct options. Using PngOptions with PngColorType.TRUECOLOR_WITH_ALPHA is appropriate for maintaining transparency.

  5. Test with Different Files: Test with various PSD files to determine if the issue is specific to the file you are using or if it is a broader problem.

Next Steps: Here’s a minimal code snippet to ensure effects are enabled and layers are processed correctly:

for layer in psd_image.layers:
    if layer.blending_options:
        layer.blending_options.are_effects_enabled = True

# Save the edited PSD file as PNG
png_options = PngOptions()
png_options.color_type = PngColorType.TRUECOLOR_WITH_ALPHA
psd_image.save(output_png_path, png_options)

If you continue to experience issues, check the release notes for any known bugs or updates related to effects handling in the version of Aspose.PSD you are using.

Please let me know if this resolves your issue!

@caseai
I can confirm issue, it looks that the Gradient Overlay on the this Smart Object can not be rendered correctly.

We have opened the following new ticket(s) with High Priority in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDNET-2565,PSDPYTHON-233

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Okay thanks. But “Layer 733” isn’t a smart object only “PLACEHOLDER1”, does it work for you there?

@caseai Layer 733 gradient rendering works acceptable, but can be improved. This issue needs additional investigation. I tried not to replace contents of Smart object, tried to use the specified gradient with regular layer instead of smart object, but the result was the same. Possible there is not only the one issue, but the combination, or this can be issue with the update of PSD Format Specification. In common cases base Layer Effects work fine, but not in this file.

Ok yes I didn’t get it to work at all. But smartobject replacement works fine. Any info on how long it’ll take until this is resolved?

@caseai the release process of Aspose.PSD 25.9 for .NET is in process, so the possible release where it will be resolved is 25.10, it will made in the beginning of October, and there will be time lag about 1 week to release Python version.