-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathframe.py
85 lines (72 loc) · 2.58 KB
/
frame.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys, os, getopt
from FramePhotoLib import PhotoFramer
def help(message = ""):
print('Help - parameters: [-h] [-d] [-r] [-y] [-p] [--passepartout[:%off_frame_size]] path/to/mockupdir path/to/photodir path/to/resultdir')
print("Available options are:")
print("-h/--help:\n\tPrint this message")
print("-d/--debug:\n\tEnable debug messages")
print("-r/--resize:\n\tAllow resizing of original photo to fit the frame")
print("-y/--yes:\n\tWill not ask any question")
print("-p:\n\tSet passepartout on frames to 95% of frame longest edge")
print("--passepartout=off_frame_size:\n\tSet passepartout on frames to off_frame_size% of frame longest edge")
print()
print("Mandatory arguments are:")
print("\tFirst a path to the directory with mockups")
print("\tSecond a path to the directory with photos to frame")
print("\tThird an existing path to the directory where to put result images")
print("\n"+message)
def main(argv):
# Look for options
try:
options, arguments = getopt.getopt(argv, 'hrypd', ["passepartout=","help","debug","resize","yes"])
except:
help("Some options are invalid")
return
# Default options
resizing = False
noask = False
passepartout = 100
debug = False
# Look for options set by user
for opt, arg in options:
if opt in ('-h','--help'):
help("Help was asked - will ignore other options and arguments")
return
elif opt in ('-d','--debug'):
debug = True
elif opt == '-p':
passepartout = 95
elif opt == '--passepartout':
try:
passepartout = int(arg)
except:
help("Passpartout option needs to be a number")
return
elif opt in ('-y','--yes'):
noask = True
elif opt in ('-r','--resize'):
resizing = True
# Check we got all the mandatory arguments
if len(arguments) != 3:
help('Not all mandatory arguments were given')
return
# Check all mandaroty arguments are directories
if not os.path.isdir(arguments[0]) or not os.path.isdir(arguments[1]) or not os.path.isdir(arguments[2]):
help('Not all path are directories')
return
# Format directories to absolute path
print()
mockupdir = os.path.abspath(arguments[0])
photodir = os.path.abspath(arguments[1])
resultdir = os.path.abspath(arguments[2])
print("Will use following directories:")
print(" Mockup: "+mockupdir)
print(" Photo: "+photodir)
print(" Result: "+resultdir)
print()
# Go do the job!
framer = PhotoFramer(mockupdir,photodir,resultdir,resizing,noask,passepartout,debug)
framer.assemble()
if __name__ == "__main__":
argv = sys.argv[1:]
main(argv)