-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
76 lines (56 loc) · 2.3 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
from flask import (
Flask, send_file, render_template, request
)
from gif_maker.lake_animations import generate_lake_brite_gif, METRICS
from gif_maker.colormap_palettes import PALETTES
from gif_maker.matrix_to_gif import normal_gif_to_lake_brite
UPLOAD_FOLDER = 'gif_maker/gif/uploads'
ALLOWED_EXTENSIONS = set(['gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
return render_template('index.html', palettes=PALETTES, metrics=METRICS)
@app.route('/lake-animation')
def lake_animation():
return send_file('gif_maker/gif/lake-animation.gif', mimetype='image/gif')
@app.route('/save-lake-animation')
def save_lake_animation():
return send_file('gif_maker/gif/lake-animation.gif', mimetype='image/gif', as_attachment=True)
@app.route('/lake-gif', methods=['POST'])
def lake_gif():
if request.method == 'POST':
metric = request.form['metric']
palette = request.form['palette']
duration = float(request.form['duration'])
tween_frames = int(request.form['tween-frames'])
empty_frames = int(request.form['empty-frames'])
if 'clip-to-lake' in request.form:
clip_to_lake = True
else:
clip_to_lake = False
return generate_lake_brite_gif(metric, palette, duration, clip_to_lake,
tween_frames, empty_frames)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/regular-gif')
def regular_gif():
return send_file('gif_maker/gif/video.gif', mimetype='image/gif')
@app.route('/save-regular-gif')
def save_regular_gif():
return send_file('gif_maker/gif/video.gif', mimetype='image/gif', as_attachment=True)
@app.route('/upload-gif', methods=['POST'])
def upload_gif():
basedir = os.path.abspath(os.path.dirname(__file__))
if request.method == 'POST':
files = request.files['file']
duration = float(request.form['gif-duration'])
if files and allowed_file(files.filename):
updir = os.path.join(basedir, 'gif_maker/gif/uploads/')
file_path = os.path.join(updir, 'regular.gif')
files.save(file_path)
return normal_gif_to_lake_brite(file_path, duration)
if __name__ == '__main__':
app.run(debug=True)