Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
narf.pl/content/assets/summer-of-creative-coding/gif-export/server.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (24 sloc)
728 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
from __future__ import absolute_import, division | |
import base64 | |
from os.path import dirname, join, realpath | |
from flask import Flask, request | |
from flask.ext.cors import CORS | |
CURRENT_DIR = dirname(realpath(__file__)) | |
IMAGES_DIR = join(CURRENT_DIR, 'images') | |
IMAGE_INDEX = 0 | |
app = Flask(__name__) | |
CORS(app) | |
@app.route('/', methods=['GET', 'POST']) | |
def index(): | |
global IMAGE_INDEX | |
png_data = request.form['imageData'].split(',')[-1] | |
decoded = base64.b64decode(png_data) | |
path = join(IMAGES_DIR, '%04d.png' % IMAGE_INDEX) | |
with open(path, 'w+') as f: | |
f.write(decoded) | |
IMAGE_INDEX += 1 | |
return '' | |
if __name__ == '__main__': | |
app.run(debug=True) |