-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathphotoshop_session.py
More file actions
28 lines (23 loc) · 927 Bytes
/
photoshop_session.py
File metadata and controls
28 lines (23 loc) · 927 Bytes
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
"""Add slate information dynamically."""
# Import built-in modules
import os
from datetime import datetime
from tempfile import mkdtemp
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()
file_path = PSD_FILE["slate_template.psd"]
with Session(file_path, action="open", auto_close=True) as ps:
layer_set = ps.active_document.layerSets.getByName("template")
data = {
"project name": "test_project",
"datetime": datetime.today().strftime("%Y-%m-%d"),
}
for layer in layer_set.layers:
if layer.kind == ps.LayerKind.TextLayer:
layer.textItem.contents = data[layer.textItem.contents.strip()]
jpg_file = os.path.join(mkdtemp("photoshop-python-api"), "slate.jpg")
ps.active_document.saveAs(jpg_file, ps.JPEGSaveOptions())
os.startfile(jpg_file)