-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-input.py
45 lines (33 loc) · 920 Bytes
/
make-input.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
import math
import os
import glob
from PIL import Image
from PIL.ExifTags import TAGS
from resizeimage import resizeimage
import time
# width x height of resized input images
canvas_size = [2500, 2500]
def get_exif(fn):
ret = {}
i = Image.open(fn)
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret
os.chdir('input')
files = glob.glob('*.jpg')
count = 0
for file in files:
time = get_exif(file)['DateTimeOriginal']
time = time.replace(':', '')
time = time.replace(' ', '_')
new_name = time + '.jpg'
os.rename(file, new_name)
# Resize images
im = Image.open(new_name)
exif = im.info['exif']
cover = resizeimage.resize_contain(im, canvas_size, bg_color=(0,0,0,1))
cover.save(new_name, im.format, quality=100, exif=exif)
print(str(count) + ' - ' + file)
count += 1