Skip to content

Commit

Permalink
no longer loads from static img
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoandrew committed Nov 13, 2016
1 parent 4f419b8 commit bd2490f
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 40 deletions.
24 changes: 0 additions & 24 deletions app/index2.html

This file was deleted.

1 change: 1 addition & 0 deletions app/static/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
padding-top: 10px;
margin-left: auto;
margin-right: auto;
max-height: 350px;
}

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
Expand Down
Binary file added app/static/impact.ttf
Binary file not shown.
Binary file added app/static/rask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/static/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/tmp/kronwall.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->
<html>
<head>
<title>Identity by HTML5 UP</title>
<title>Meme Generator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="assets/js/html5shiv.js"></script><![endif]-->
Expand Down Expand Up @@ -94,7 +94,8 @@ <h2>Extra Stuff!</h2>
type: "GET",
data: {range: document.getElementById("myRange").value, range1: document.getElementById("myRange1").value},
success: function (response) {
$('#imagediv').attr('src', response);
$('#imagediv').attr('src', '/send_img?' + new Date().getTime());

},
});
});
Expand Down
Binary file added app/tmp/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/tmp/test2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 26 additions & 14 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Flask
from flask import send_from_directory
from flask import render_template, Response, request, redirect, url_for
from flask import send_from_directory, make_response
from flask import render_template, Response, request, redirect, url_for, send_file
from werkzeug import secure_filename
from PIL import Image
from PIL import ImageDraw
Expand All @@ -14,26 +14,31 @@ def draw_caption(img, text, top=False):
draw = ImageDraw.Draw(img)
#Find a suitable font size to fill the entire width:
w = img.size[0]
s = 100
s = 60
while w >= (img.size[0] - 20):
#font = ImageFont.truetype("arial.ttf", 15)
w, h = draw.textsize(text)
#font = ImageFont.load_default()
font = ImageFont.truetype("./static/impact.ttf", size=s)
w, h = draw.textsize(text, font=font)
s -= 1
if s <= 12: break
#Draw the text multiple times in black to get the outline:
for x in range(-3, 4):
for y in range(-3, 4):
draw_y = y if top else img.size[1] - h + y
draw.text((10 + x, draw_y), text, fill='black')
draw.text((10 + x, draw_y), text, font=font, fill='black')
#Draw the text once more in white:
draw_y = 0 if top else img.size[1] - h
draw.text((10, draw_y), text, fill='white')
draw.text((10, draw_y), text, font=font, fill='white')

@app.route('/')
@app.route('/index')
def index():
return render_template("index.html")

@app.route('/send_img')
def send_img():
return send_from_directory('./tmp', 'test.jpg')

@app.route('/get_meme', methods=['GET', 'POST'])
def get_memes():
args = request.args.to_dict()
Expand All @@ -43,18 +48,25 @@ def get_memes():
range2 = args['range1']

#put text here
sample_txt = "sample text"
sample_txt = "sample text 3"

#open image here
#open image to use here
img = Image.open("./static/kronwall.jpg")

#add caption need to fix font size

# resize to height 300
baseheight = 300
hpercent = (baseheight/float(img.size[1]))
wsize = int((float(img.size[0])*float(hpercent)))
img = img.resize((wsize,baseheight), Image.ANTIALIAS)

#add caption
draw_caption(img, sample_txt, top=True)

#save to show
img.save("./static/test.jpg")
resp = Response("./static/test.jpg")
return resp
#save to show. THE FILE NAME HERE WILL BE USED AGAIN AT SEND_IMG
img.save("./tmp/test.jpg")
#Response here is never used. Doesnt really matter
return Response("./tmp/test.jpg")

if __name__ == '__main__':
app.run()

0 comments on commit bd2490f

Please sign in to comment.