-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-psd.py
57 lines (48 loc) · 1.71 KB
/
convert-psd.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#www.lasselauch.com/lab/
#Use at your own risk
import sys
import os
from psd_tools import PSDImage
def getsuffix(fn):
f, ext = os.path.splitext(fn)
if not ' ' in ext:
return f, ext
def ExportLayers(psd, folder, f):
for layer in psd.layers:
filename = "%s_%s" % (f, layer.name)
outfile = os.path.join(folder, filename + sys.argv[2])
if layer.visible:
layer = layer.as_PIL()
layer.save(outfile)
print "\n..........................................\n"
print 'Exported Layer: "%s" from "%s.psd"' % (os.path.basename(outfile), os.path.basename(f))
print "\n.........................................."
#infile = sys.argv[1]
#LAYERS = False
try:
LAYERS = sys.argv[3]
except:
LAYERS = False
for infile in sys.argv[1:]:
if os.path.isdir(infile):
os.chdir(infile)
files = filter(os.path.isfile, os.listdir(infile))
files = [os.path.join(infile, f) for f in files] # add path to each file
else:
files = [infile]
for infile in files:
folder, fn = os.path.split(infile)
f, ext = getsuffix(infile)
if ext == '.psd':
psd = PSDImage.load(infile)
#Export all visibile Layers from PSD
if LAYERS:
ExportLayers(psd, folder, f)
exit()
#Convert PSD to PNG
merged = psd.as_PIL()
outfile = os.path.join(folder, f + sys.argv[2])
merged.save(outfile)
print "\n..........................................\n"
print 'Converted "%s" to "%s"' % (os.path.basename(infile), os.path.basename(outfile))
print "\n.........................................."