Skip to content

Commit

Permalink
hanse-web
Browse files Browse the repository at this point in the history
  • Loading branch information
halcy committed Dec 21, 2018
1 parent 569e052 commit ed346f3
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 12 deletions.
41 changes: 34 additions & 7 deletions hanse_web.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from flask import Flask, request, send_from_directory, render_template, send_file
app = Flask(__name__, static_url_path='')

base_path = "images/"

import numpy as np
from io import BytesIO
import glob
Expand All @@ -13,7 +15,7 @@

pal_styles = ""
for i in range(16):
col = np.floor(np.array(ansi_graphics.cga_colour(i)) * 255.0)
col = np.array(np.floor(np.array(ansi_graphics.cga_colour(i)) * 255.0), 'int')
pal_entry = ".fg" + str(i) + "{\n"
pal_entry += " color: rgb(" + str(col[0]) + ", " + str(col[1]) + ", " + str(col[2]) + ");\n"
pal_entry += "}\n\n"
Expand All @@ -25,19 +27,34 @@

@app.route('/')
def file_list():
file_list = list(glob.glob('*.ans'))
file_list = list(glob.glob(base_path + '*.ans'))
list_html = '<h1>Files</h1><div style="text-align: left; font-size: 28px; width: 600px;">'
for ansi_file in file_list:
ansi_file = ansi_file[len(base_path):]
list_html += '--> <a href="/view/' + ansi_file + '">' + ansi_file + '</a><br/>'
list_html += "</div>"
return(render_template("default.html", title="files", content=list_html))


@app.route('/gallery')
def gallery():
file_list = list(glob.glob(base_path + '*.ans'))
list_html = '<h1>Gallery</h1><div style="text-align: left; font-size: 28px; width: 600px;">'
for ansi_file in file_list:
ansi_file = ansi_file[len(base_path):]
list_html += '<a href="/image/' + ansi_file + '"><img src="/image/' + ansi_file + '?thumb"></img></a><br/>'
list_html += "</div>"
return(render_template("default.html", title="files", content=list_html))

@app.route('/view/<path:path>')
def render_ansi(path):
wide_mode = False
if request.args.get('wide', False) != False:
wide_mode = True

try:
ansi_image = AnsiImage(ansi_graphics)
ansi_image.clear_image(80, 24)
ansi_image.load_ans(path, False)
ansi_image.load_ans(base_path + path, wide_mode = wide_mode)
width, height = ansi_image.get_size()
except:
return(render_template("default.html", title="Loading error, sorry."))
Expand All @@ -55,16 +72,26 @@ def render_ansi(path):
@app.route('/image/<path:path>')
def render_ansi_png(path):
transparent = False
if request.args.get('transparent', False) != False:
wide_mode = False
thumb = False

if request.args.get('transparent', None) != None:
transparent = True
if request.args.get('wide', None) != None:
wide_mode = True
if request.args.get('thumb', None) != None:
thumb = True

try:
ansi_image = AnsiImage(ansi_graphics)
ansi_image.clear_image(80, 24)
ansi_image.load_ans(path, False)
ansi_image.clear_image(1000, 1000)
ansi_image.load_ans(base_path + path, wide_mode = wide_mode)
bitmap = ansi_image.to_bitmap(transparent = transparent)
except:
return(render_template("default.html", title="Loading error, sorry."))

if thumb == True:
bitmap.thumbnail((128, 128))
img_io = BytesIO()
bitmap.save(img_io, 'PNG')
img_io.seek(0)
Expand Down
1 change: 1 addition & 0 deletions images/guy4.ans

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions images/meow.ans

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions images/robot2.ans

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions images/sgtcat.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
                                                                              
                                                                              
                                                                              
                                                                              
         ����������������������������������������������� Sgt. Cat ����        
         ����������������                                            �        
         ��   /\___/\   �  Quick! You must defend cat planet against �        
         �� =< � w � >= �  the alien invasion!                       �        
         ��   �    �   �                                            �        
         ����������������  You are our only hope!                    �        
         �                                                         �        
         �������������������������������������������������������������        
                                                                              
                                                                              
                                                                              
                                                                              
                                                                              
1 change: 1 addition & 0 deletions images/svatgbreak2.ans

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions images/valid.ans

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions images/yeehaw.ans

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions templates/default.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<head>
<meta name="format-detection" content="telephone=no">
<title>HANSEWeb - {{title}}</title>
<style type="text/css">
@font-face {
Expand All @@ -9,26 +10,41 @@
font-style: normal;
}

body, pre, h1 {
line-height: 1;
body, div, pre, h1, a, a:link, a:active {
font-size: 100%;
line-height: 1.0;
font-family: 'cp866_8x16';
font-weight: normal;
font-style: normal;
letter-spacing: 0px;
background: #000000;
color: #FFFFFF;
font-smooth: never;
-webkit-font-smooth: none;
-moz-font-smooth: none;
-moz-osx-font-smooth: none;
filter: contrast(1);
}
h1 {
font-size: 40px;
}
img {
display: inline-block;
max-width: 128px;
max-height: 128px;
float: left;
}
{{styles}}
</style>
</head>
<pre>
<body>
<div style="text-align: center">
<pre>
{{content|safe}}
</pre>
{% if show_dl %}
<h1>{{ title }} - <a href="/image/{{ title }}">download png</a> - <a href="/image/{{ title }}?transparent=True">with transparent bg</a></h1>
<h1>{{ title }} - <a href="/image/{{ title }}">download png</a> - <a href="/image/{{ title }}?transparent=True">with transparent bg</a></h1>
{% endif %}
</div>
</pre>
</body>
</html>

0 comments on commit ed346f3

Please sign in to comment.