img_process.py
1.63 KB
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
import os, sys
from PIL import Image
def make_img(filename):
try:
with Image.open(filename + '.png') as im:
print("File ("+filename +".png)")
if im.width<im.height :
crop_size = (im.height-im.width)/2
area = (0, int(crop_size), im.width, int(crop_size)+im.width)
elif im.width>im.height :
crop_size = (im.width-im.height) / 2
area = (int(crop_size), 0, int(crop_size)+im.height, im.height)
else :
area = (0, 0, im.width , im.height)
cropped_img = im.crop(area)
cropped_img.thumbnail((32, 32))
cropped_img.save(filename + "_0.png")
im2 = cropped_img.rotate(90)
im2.save(filename + "_90.png")
im3 = cropped_img.rotate(180)
im3.save(filename + "_180.png")
im4 = cropped_img.rotate(270)
im4.save(filename + "_270.png")
im_transpose = cropped_img.transpose(Image.FLIP_LEFT_RIGHT)
im5 = im_transpose
im5.save(filename + "_transpose_0.png")
im6 = im_transpose.rotate(90)
im6.save(filename + "_transpose_90.png")
im7 = im_transpose.rotate(180)
im7.save(filename + "_transpose_180.png")
im8 = im_transpose.rotate(270)
im8.save(filename + "_transpose_270.png")
os.remove(filename+'.png')
except IOError:
print("No file ("+filename +".png)")
for i in range(0,1000):
filename = str(i)
make_img(filename)
filename = '0' + str(i)
make_img(filename)