panzer meme

This commit is contained in:
Xevion
2019-07-11 21:30:40 -05:00
parent 5022485ff6
commit a923f78218
4 changed files with 35 additions and 7 deletions

View File

@@ -3,8 +3,10 @@ from app.models import User, Search
from app.forms import LoginForm, RegistrationForm from app.forms import LoginForm, RegistrationForm
from app.custom import require_role from app.custom import require_role
from werkzeug.urls import url_parse from werkzeug.urls import url_parse
from flask import render_template, redirect, url_for, flash, request, jsonify, abort from flask import render_template, redirect, url_for, flash, request, jsonify, abort, send_file
from flask_login import current_user, login_user, logout_user, login_required from flask_login import current_user, login_user, logout_user, login_required
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
import requests import requests
import xmltodict import xmltodict
import base64 import base64
@@ -22,6 +24,29 @@ def strgen(length):
def unauthorized(e): def unauthorized(e):
return redirect(url_for('login')) return redirect(url_for('login'))
def serve_pil_image(pil_img):
img_io = BytesIO()
pil_img.save(img_io, 'JPEG', quality=50)
img_io.seek(0)
return send_file(img_io, mimetype='image/jpeg')
@app.route('/panzer/')
@app.route('/panzer/<string>')
def panzer(string='bionicles are cooler than sex'):
string = string.replace('+', ' ')
image = create_panzer(string)
return serve_pil_image(image)
def create_panzer(string):
img = Image.open("./app/static/panzer.jpeg")
draw = ImageDraw.Draw(img)
font1 = ImageFont.truetype('./app/static/arial.ttf', size=30)
font2 = ImageFont.truetype('./app/static/arial.ttf', size=30)
draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1)
draw.text((250, 500), string, font=font2)
return img
@app.route('/profile/') @app.route('/profile/')
@login_required @login_required
def profile(): def profile():

BIN
app/static/arial.ttf Normal file
View File

Binary file not shown.

BIN
app/static/panzer.jpeg Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -27,21 +27,25 @@
}); });
</script> </script>
<style type="text/css"> <style type="text/css">
.tab-left { .tab-left {
padding-left: 3rem; padding-left: 3rem;
} }
</style> </style>
{% endblock head %} {% endblock head %}
{% block dashboard_body %} {% block dashboard_body %}
<section> <section>
<h1 class="title">Profile Settings</h1> <h1 class="title">Profile Settings</h1>
<!-- Profile Email Settings Form -->
<form class="form-ajax" action="" method="POST" novalidate> <form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<div class="field tab-left"> <div class="field tab-left">
<h4 class="title is-4">{{ form.show_email.label }}</h4> <h4 class="title is-4">{{ form.show_email.label }}</h4>
{{ form.show_email() }} {{ form.show_email(class="radio") }}
</div> </div>
</form>
<!-- Profile Picture Form -->
<form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<h4 class="title is-4">{{ form.profile_picture_file.label }}</h4> <h4 class="title is-4">{{ form.profile_picture_file.label }}</h4>
{{ form.profile_picture_file(class="") }} {{ form.profile_picture_file(class="") }}
@@ -59,7 +63,6 @@
</span> </span>
</label> </label>
</div> </div>
</div> </div>
{{ form.submit(class="button is-danger") }} {{ form.submit(class="button is-danger") }}