diff --git a/server.py b/server.py index e5bba39..6ad1025 100755 --- a/server.py +++ b/server.py @@ -15,6 +15,7 @@ import os import setproctitle + MAIN_PORT = 42010 DATABASE_PORT = 42011 @@ -75,18 +76,41 @@ def graceful_exit(sig=None,frame=None): @webserver.route("/images/") @webserver.route("/images/") def static_image(pth): - return static_file("images/" + pth,root="") + small_pth = pth.split(".") + small_pth.insert(-1,"small") + small_pth = ".".join(small_pth) + if os.path.exists("images/" + small_pth): + response = static_file("images/" + small_pth,root="") + else: + try: + from wand.image import Image + img = Image(filename="images/" + pth) + x,y = img.size[0], img.size[1] + smaller = min(x,y) + if smaller > 300: + ratio = 300/smaller + img.resize(int(ratio*x),int(ratio*y)) + img.save(filename="images/" + small_pth) + response = static_file("images/" + small_pth,root="") + else: + response = static_file("images/" + pth,root="") + except: + response = static_file("images/" + pth,root="") + + #response = static_file("images/" + pth,root="") + response.set_header("Cache-Control", "public, max-age=604800") + return response -@webserver.route("/") +#@webserver.route("/") @webserver.route("/") @webserver.route("/") @webserver.route("/") @webserver.route("/") @webserver.route("/") def static(name): - return static_file("website/" + name,root="") - - + response = static_file("website/" + name,root="") + response.set_header("Cache-Control", "public, max-age=604800") + return response @webserver.route("/") def static_html(name):