-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin_images.py
57 lines (43 loc) · 1.6 KB
/
join_images.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
# joins two image together either vertically or horizontally.
# optional pad amt
# if joining horizontally, first picture is left, second picture is right
# if joining vertically, first picture is top, second picture is bottom
import sys
import Image
def join(input1, input2, output, mode, pad):
im1 = Image.open(input1)
im2 = Image.open(input2)
if mode.lower() == 'h':
# join horizontally
width = im1.size[0] + im2.size[0] + pad
height = max(im1.size[1], im2.size[1])
im = Image.new('RGB', (width, height))
im.paste(im1, (0, 0))
im.paste(im2, (im1.size[0] + pad, 0))
elif mode.lower() == 'v':
# join vertically
width = max(im1.size[0], im2.size[0])
height = im1.size[1] + im2.size[1] + pad
im = Image.new('RGB', (width, height))
im.paste(im1, (0, 0))
im.paste(im2, (0, im1.size[1] + pad))
im.save(output)
#print 'output written to', output
def usage():
print 'usage: <input1> <input2> <output> [\'h\'|\'v\'] [pad amt]'
if __name__ == '__main__':
if len(sys.argv) < 4:
usage()
else:
if len(sys.argv) == 4:
# let the default be horizontal with zero pad
join(sys.argv[1], sys.argv[2], sys.argv[3], 'h', 0)
else:
orientation = sys.argv[4].lower()
if orientation == 'h' or orientation == 'v':
pad = 0
if len(sys.argv) > 5:
pad = int(sys.argv[5])
join(sys.argv[1], sys.argv[2], sys.argv[3], orientation, pad)
else:
usage()