Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 - Change visibility of PSD layers programmatically

Tags:

python-3.x

Is possible to programmatically change PSD layer visibility in a PSD, without use Photoshop?

I did check various implementation of PSD libraries for Python, but the best they do is to return the visibility value (like psd_tools); but the visible property is read only, so I can't change it.

I wish there was a way to be able to extract and manipulate groups and layers in PSD files, directly from Python; but the best I can do is to use psd_tools to retrieve layers and stack them together; after export them as PNG; although this is not ideal


1 Answers

If anybody is wondering... You can actually turn visibility on layers with psd-tools. And if you save that PSD with psd-tools, it will show properly when opened with Photoshop. However, if you save it to PNG, it won't show your changes, unless you set param force to True when calling .compose() function. It took me some time to realize that.

Example:

from psd_tools import PSDImage

psd = PSDImage.open( filename )
psd[0].visible = False             # Set first layer to invisible
image = psd.compose( force=True )  # Very important to set force param!
image.save( "output.png" )
like image 85
vedranm Avatar answered Oct 14 '25 20:10

vedranm