Skip to content

Instantly share code, notes, and snippets.

@di
Last active December 18, 2015 03:29
Show Gist options
  • Save di/5718209 to your computer and use it in GitHub Desktop.
Save di/5718209 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
function reloadpic() {
document.images["screen"].src = "screen.png?random=" + new Date().getTime();
setTimeout("reloadpic();", 500);
}
onload = reloadpic;
</script>
</head>
<body>
<img width="100%" id="screen">
</body>
</html>
#!/usr/bin/python
import pyscreenshot
import flask
from StringIO import StringIO
app = flask.Flask(__name__)
@app.route('/screen.png')
def serve_pil_image():
img_io = StringIO()
pyscreenshot.grab().save(img_io, 'PNG', quality=50)
img_io.seek(0)
return flask.send_file(img_io, mimetype='image/png')
@app.route('/')
def serve_img():
return flask.render_template('screen.html')
if __name__ == "__main__":
app.run(host= '0.0.0.0', debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment