Commit 369d71eb by triazo

Add the compress stuffz

parents
#!/usr/bin/python
from PIL import Image
import flask
import os
import shutil
DEBUG = True
ShirleyPath = "./Shirley.jpg"
TempPath = "./shirley.jpg"
TempStaticPath = "./static/shirley.jpg"
CountFile = "visits"
app = flask.Flask(__name__)
app.config.from_object(__name__)
def shirleyTierPath(t):
return "ShirleyTier"+str(t)+".jpg"
def compressTier(t):
if os.path.isfile(shirleyTierPath(t)):
return
compressTier(t - 1)
im1 = Image.open(shirleyTierPath(t-1))
im1 = im1.resize((int(float(im1.size[0])*.95), int(float(im1.size[1])*0.95)), Image.ANTIALIAS)
im1.save(shirleyTierPath(t), "JPEG", quality=10)
def compress(level):
q = 10000 - (level % 9000)
compressTier(level / 9000)
im1 = Image.open(shirleyTierPath(level / 9000))
im1.save(TempStaticPath, "JPEG", quality=q/90)
def getCount():
visits = 0
if os.path.isfile(CountFile):
with open(CountFile, 'r') as f:
visits = int(f.read())
with open(CountFile, 'w') as f:
f.write(str(visits + 1))
return visits
@app.route("/")
def showShirley():
visits = getCount()
compress(visits)
return flask.render_template("RIP.html", v=visits)
@app.route("/Shirley.jpg")
def giveShirley():
print("showing shirley")
return app.send_static_file(TempPath)
if __name__ == "__main__":
app.run(port = 31337)
<html>
<head>
<title>RIP SHIRLEY</title>
<style>
html, body, div {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
#shirley {
width: 100%;
}
#count {
background-color: white;
position: absolute;
top: 0;
width: 500px;
left: calc(50% - 250px);
margin: 0 auto;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
font-size: 30;
}
#help {font-size: 16}
</style>
</head>
<body>
<img id="shirley" src="Shirley.jpg" />
<center>
<div id="count">Shirley has been RIP'd {{v}} times<br /><span id="help">Every
View increases compression</span></div>
</center>
</body>
</html>
adam@zinc.862:1452353077
\ No newline at end of file
<html>
<head>
<title>RIP SHIRLEY</title>
<style>
html, body, div {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
#shirley {
width: 100%;
}
#count {
background-color: white;
position: absolute;
top: 0;
width: 500px;
left: calc(50% - 250px);
margin: 0 auto;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
font-size: 30;
}
#help {font-size: 16}
</style>
</head>
<body>
<img id="shirley" src="Shirley.jpg" />
<center>
<div id="count">Shirley has been RIP'd {{v}} times<br /><span id="help">Every
View increases compression</span></div>
</center>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment