-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
43 lines (32 loc) · 913 Bytes
/
generator.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
from glob import glob
from PIL import Image, ExifTags
from jinja2 import Template, Environment, FileSystemLoader
def main():
env = Environment(loader=FileSystemLoader('templates'))
image_template = env.get_template('gallery.html')
images = glob("dist/media/*.jpg")
image_list = []
for image in images:
img = Image.open(image)
width, height = img.size
tags = {
ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in ExifTags.TAGS
}
img.close()
if (width / height) >= .8:
orientation = 'landscape'
else:
orientation = 'portrait'
image_list.append({
"path": image.replace('dist/',''),
"desc": tags['ImageDescription'],
"artist": tags['Artist'],
"orientation": orientation
})
output = image_template.render(images=image_list)
with open("dist/2017-christmas-artwork.html", "wb") as f:
f.write(output)
if __name__ == "__main__":
main()