-
Notifications
You must be signed in to change notification settings - Fork 0
/
3x3.py
66 lines (48 loc) · 1.52 KB
/
3x3.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
import os
import sys
import time
from PIL import Image
def main(width, brightness):
imgList = []
n = 0
margin = width // 100
sWidth = (width - (4 * margin)) // 3
uWidth = sWidth + margin
for file in os.listdir("."):
if file != 'out.png' and (file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg")):
imgList.append(file)
n += 1
if n == 9:
break
imgList.sort()
print(imgList)
img = Image.new('RGB', (width, width), (brightness, brightness, brightness))
x = 0
y = 0
for file in imgList:
image = Image.open(file, 'r')
origWidth = image.size[0]
origHeight = image.size[1]
if origWidth > origHeight: # if landscape
cropped = (origWidth - origHeight) // 2
image = image.crop((cropped, 0, cropped + origHeight, origHeight))
else: # if portrait
cropped = (origHeight - origWidth) // 2
image = image.crop((0, cropped, origWidth, cropped + origWidth))
image = image.resize((sWidth, sWidth), Image.ANTIALIAS)
img.paste(image, ((x * uWidth) + margin, (y * uWidth) + margin))
print (file)
x += 1
if x == 3:
x = 0
y += 1
img.save('out.png')
if __name__ == "__main__":
argLen = len(sys.argv)
w = 1000
b = 0
if (argLen >= 2):
w = int(sys.argv[1])
if argLen == 3:
b = int(sys.argv[2])
main(w, b)