-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathexport_layers_as_png.py
More file actions
40 lines (31 loc) · 1.08 KB
/
export_layers_as_png.py
File metadata and controls
40 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Export every layer as a .png file."""
# Import built-in modules
import os
import examples._psd_files as psd # Import from examples.
from photoshop import Session
# Import third-party modules
# Import local modules
PSD_FILE = psd.get_psd_files()
def hide_all_layers(layers):
for layer in layers:
layer.visible = False
def main():
psd_file = PSD_FILE["export_layers_as_png.psd"]
with Session(psd_file, action="open") as ps:
doc = ps.active_document
options = ps.PNGSaveOptions()
options.compression = 1
layers = doc.artLayers
for layer in layers:
hide_all_layers(layers)
layer.visible = True
layer_path = os.path.join(doc.path, layer.name)
print(layer_path)
if not os.path.exists(layer_path):
os.makedirs(layer_path)
image_path = os.path.join(layer_path, f"{layer.name}.png")
doc.saveAs(image_path, options=options, asCopy=True)
ps.alert("Task done!")
ps.echo(doc.activeLayer)
if __name__ == "__main__":
main()