How to Save and Export PSD Documents in Python
This guide shows how to save an edited document to a file path, to an
open stream, and how to dispose of a loaded image afterward.
PsdImage.save is the single public entry point for writing a document
back out — it accepts either a file path or an already-open writable
stream. The low-level section writer that does the actual byte encoding is
an internal implementation detail, not something you call directly.
Step-by-Step Guide
Step 1: Install the Package
pip install aspose-psd-fossStep 2: Import Required Classes
PsdImage is the only class this guide’s examples need:
from aspose_psd_foss.psdimage import PsdImageStep 3: Save to a File Path
Load a document, make an edit, then save it back to a file path:
image = PsdImage.load("input.psd")
image.layers[0].is_visible = False
image.save("output.psd")Step 4: Save to an Open Stream
Passing a stream instead of a path leaves the stream open after saving — you control when to close it:
with open("output.psd", "wb") as stream:
image.save(stream)Step 5: Dispose the Image
Release the resources the loaded PsdImage holds once you’re done with it:
image.dispose()Common Issues and Fixes
RuntimeError: PsdImage has been disposed. when calling save. The
image was already disposed (via dispose() or a with block that exited)
before save was called. Call save before disposing.
PsdSaveException about a Pascal string length. A string value
exceeds 255 bytes — see
Handling PSD Core Exceptions
and Troubleshooting.
No way to force a PSD or PSB container on save. There is no public
API to choose the output container format — a save always mirrors
whichever format (is_large_document / is_psb) the document was loaded
with. If you need a different container format, there is no supported
conversion path in this FOSS build.
Frequently Asked Questions
Does saving to a stream close the stream afterward?
No — when you pass a stream to save, the stream is left open afterward
so you control its lifecycle (see Step 4). Saving to a file path, by
contrast, opens and closes the file internally.
Can I call the internal section writer directly instead of save?
No — the section-level writer is an internal implementation detail invoked
by PsdImage.save. There is no documented, supported way to write a
document outside of calling save on a PsdImage instance.