AsposePSD states that a valid PSD file is not a valid PSD

This python script

from aspose.psd import Image
from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers.smartobjects import SmartObjectLayer
from aspose.psd.imageloadoptions import PsdLoadOptions
from aspose.psd.imageoptions import PngOptions

def find_smart_layers(psd_file_path):
with Image.load(psd_file_path) as image:
if isinstance(image, PsdImage):
psd_image = image
print(f"Searching for smart layers in: {psd_file_path}“)
found_smart_layers = False
for i, layer in enumerate(psd_image.layers):
if isinstance(layer, SmartObjectLayer):
print(f” Found Smart Object Layer: ‘{layer.name}’ at index {i}“)
found_smart_layers = True
if not found_smart_layers:
print(” No Smart Object Layers found in this PSD file.“)
else:
print(f"The file ‘{psd_file_path}’ is not a valid PSD image.”)

file_path = r"D:\Healthy\Design\Mockups\LandscapeMockups\Automation\001.psd"
find_smart_layers(file_path)

returns

“The file ‘D:\Healthy\Design\Mockups\LandscapeMockups\Automation\001.psd’ is not a valid PSD image.”

for all PSD files.

I have opened the PSD files and saved them again with no difference.

I’m using this test before purchasing a license. If I can’t get this working then I’ll need to look elsewhere.

Thanks for any help!

@blstraub

It seems you’re encountering an issue where Aspose.PSD is unable to recognize your PSD files as valid. Here are a few steps you can take to troubleshoot this problem:

  1. File Integrity: Ensure that the PSD files are not corrupted. You can try opening them in Adobe Photoshop or another image editing software to verify their integrity.

  2. File Format: Make sure that the files are indeed in the PSD format. Sometimes, files may have a .psd extension but are not actually in the correct format.

  3. Library Version: Check if you are using the latest version of the Aspose.PSD library. If not, consider updating to the latest version as it may contain bug fixes and improvements.

  4. Sample Code: Here’s a simple example of how to load a PSD file using Aspose.PSD in Python:

    import aspose.psd as psd
    
    # Load the PSD file
    try:
        image = psd.Image.load("D:\\Healthy\\Design\\Mockups\\LandscapeMockups\\Automation\\001.psd")
        print("PSD file loaded successfully.")
    except Exception as e:
        print(f"Error: {e}")
    
  5. Testing with Different Files: If possible, test with different PSD files to see if the issue persists across all files or is specific to certain ones.

If you continue to face issues, consider reaching out to Aspose support or checking their forums for similar problems and solutions.

Feel free to ask if you have any more questions!

If I change the script to read this way:

import aspose.psd as psd
from aspose.psd import Image
from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers.smartobjects import SmartObjectLayer
from aspose.psd.imageloadoptions import PsdLoadOptions
from aspose.psd.imageoptions import PngOptions

def find_smart_layers(psd_file_path):

try:
    image = psd.Image.load(psd_file_path)
except Exception as e:
    print(f"Error: {e}")

if isinstance(image, PsdImage):
    psd_image = image
    print(f"Searching for smart layers in: {psd_file_path}")
    found_smart_layers = False
    for i, layer in enumerate(psd_image.layers):
        if isinstance(layer, SmartObjectLayer):
            print(f"  Found Smart Object Layer: '{layer.name}' at index {i}")
            found_smart_layers = True
    if not found_smart_layers:
        print("  No Smart Object Layers found in this PSD file.")
    else:
        print(f"The file '{psd_file_path}' is not a valid PSD image.")
else:
    print("not image instance")

file_path = r"D:\Healthy\Design\Mockups\LandscapeMockups\Automation\001.psd"
find_smart_layers(file_path)

It returns “not image instance”.

@blstraub please check these examples: GitHub - aspose-psd/Aspose.PSD-for-Python-Net: Aspose.PSD for Python examples, plugins and showcases

Usually, using Aspose.PSD for Python via .NET the following cast is needed:

# Open File using Aspose.PSD for Python
with Image.load(sourceFile, loadOptions) as image:
    # Types of Aspose.PSD can be casted
    psdImage = cast(PsdImage, image)
    

    # To check the class of objeectg please try this:
    layer = psdImage.layers[3]
    if is_assignable(layer, SmartObjectLayer):
        print(f"  Found Smart Object Layer: '{layer.name}' at index 3")
  

If the issue still presented after this code, please provide information about you environment, version of Aspose.PSD and please provide the input file to help us to reproduce the issue.

Thank you. I’m trying run these examples locally on a Windows 11 machine.

I feel like I’m making some progress but I am getting import errors, as shown in this screenshot:

image.png (135.3 KB)

@blstraub please check that the Aspose.PSD for Python is installed in the same Python environment in which you try to run examples. Run in the your Python IDE the following consoole command:

pip install aspose-psd

Dmitriy: I, too, suspected that the Python installation on this test machine was part of the problem.

I deleted Python and all of its resources and then reinstalled Python, VS Code and AsposePSD.

The errors that I were getting before continue. This simple program:

from typing import cast
from aspose.psd import Image
from aspose.psd.imageloadoptions import PsdLoadOptions
from aspose.psd.fileformats.psd import PsdImage

load_options = PsdLoadOptions()
file_path = r"D:\Tests\003.psd"

with Image.load(file_path, load_options) as image:
psdImage = cast(PsdImage, image)

for layer in psdImage.layers:
print(f"Layer Name: {layer.name}")

image.dispose()

returns the following error message:

Traceback (most recent call last):
** File “d:\Healthy\Python\layer test 2.py”, line 17, in **
** for layer in psdImage.layers:**
** ^^^^^^^^^^^^^^^**
AttributeError: ‘aspose.psd.Image’ object has no attribute ‘layers’

There are three underlying problems: the imports for aspose.psd, aspose.psd.imageloadoptions and aspose.psd.fileformats.psd could not be resolved by Pylance.

Suggestions?

And the obvious question: Does AsposePDS actually work with Python in a Windows machine?

Thanks again for your help!

I have verified that aspose is installed in the same folder as the other installed packages (i.e., pillow, photoshop).

Another question: This VSCode installation only includes the Microsoft Interpreter for Python 3.13.7.

Is it possible that this interpreter is not compatible with AsposePSD?

As another test, I installed pds-tools in the same manner as AsposePSD. It worked correctly immediately.

I installed this version: aspose_psd-25.8.0-py3-none-win_amd64.whl

Is it possible that I have installed the wrong product?

Thanks!