-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
52 lines (43 loc) · 1.31 KB
/
server.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
import os
import cherrypy
from io import BytesIO
from PIL import Image
from uuid import uuid4
from giffy import make_gif, save_gif
class ImageMorpher(object):
def upload(self, file_1, file_2):
def readall(file_obj):
img = bytes()
while True:
data = file_obj.file.read(8192)
if not data:
break
img = img + data
return img
img1 = readall(file_1)
img2 = readall(file_2)
img1 = Image.open(BytesIO(img1))
img2 = Image.open(BytesIO(img2))
imgs = make_gif(img1, img2)
uuid = uuid4().hex
save_gif(imgs, 'static/generated/'+uuid+'.gif')
raise cherrypy.HTTPRedirect("static/generated/"+uuid+".gif")
upload.exposed = True
if __name__ == '__main__':
cherrypy.config.update({
'server.socket_host': '0.0.0.0',
'server.socket_port': 9722,
})
conf = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '',
'tools.staticdir.root': os.path.abspath(os.getcwd()),
'tools.staticdir.index': 'static/index.html'
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'static'
}
}
cherrypy.quickstart(ImageMorpher(), '/', conf)