Resize flag images in the backend.

master
Pacman Ghost 6 years ago
parent 42f6f7a143
commit f28b2cf363
  1. 4
      _freeze.py
  2. 1
      setup.py
  3. 10
      vasl_templates/webapp/__init__.py
  4. 2
      vasl_templates/webapp/data/default-template-pack/atmm.j2
  5. 2
      vasl_templates/webapp/data/default-template-pack/baz.j2
  6. 2
      vasl_templates/webapp/data/default-template-pack/mol-p.j2
  7. 2
      vasl_templates/webapp/data/default-template-pack/mol.j2
  8. 2
      vasl_templates/webapp/data/default-template-pack/ob_ordnance.j2
  9. 2
      vasl_templates/webapp/data/default-template-pack/ob_setup.j2
  10. 2
      vasl_templates/webapp/data/default-template-pack/ob_vehicles.j2
  11. 2
      vasl_templates/webapp/data/default-template-pack/pf.j2
  12. 2
      vasl_templates/webapp/data/default-template-pack/piat.j2
  13. 2
      vasl_templates/webapp/data/default-template-pack/psk.j2
  14. 30
      vasl_templates/webapp/snippets.py

@ -79,8 +79,8 @@ def map_dir( src, dest ): #pylint: disable=missing-docstring
args.extend( [ "--add-data", src + os.pathsep + dest ] )
map_dir( "vasl_templates/ui", "vasl_templates/ui" )
map_dir( "vasl_templates/resources", "vasl_templates/resources" )
map_dir( "vasl_templates/webapp/static", "static" )
map_dir( "vasl_templates/webapp/templates", "templates" )
map_dir( "vasl_templates/webapp/static", "vasl_templates/webapp/static" )
map_dir( "vasl_templates/webapp/templates", "vasl_templates/webapp/templates" )
if sys.platform == "win32":
args.append( "--noconsole" )
args.extend( [ "--icon", APP_ICON ] )

@ -21,6 +21,7 @@ setup(
# nb: WebEngine seems to be broken in 5.10.1 :-/
"PyQT5==5.10.0",
"pyyaml==3.13",
"pillow==5.3.0",
"click==6.7",
],
extras_require = {

@ -29,15 +29,7 @@ def load_debug_config( fname ):
# ---------------------------------------------------------------------
# initialize Flask
if getattr( sys, "frozen", False ):
# NOTE: The support directories must have been set up by pyinstaller (via --add-data).
meipass = sys._MEIPASS #pylint: disable=no-member,protected-access
app = Flask( __name__,
template_folder = os.path.join( meipass, "templates" ),
static_folder = os.path.join( meipass, "static" )
)
else:
app = Flask( __name__ )
app = Flask( __name__ )
# load the application configuration
config_dir = os.path.join( BASE_DIR, "config" )

@ -16,7 +16,7 @@ td { margin: 0 ; padding: 0 ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}Anti-Tank Magnetic Mines
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}Anti-Tank Magnetic Mines
<tr>
<td style="padding:2px 5px;">

@ -18,7 +18,7 @@ td.r { text-align: right ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}Bazooka {%if BAZ_TYPE%} ('{{BAZ_TYPE}}) {%endif%}
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}Bazooka {%if BAZ_TYPE%} ('{{BAZ_TYPE}}) {%endif%}
<tr>

@ -19,7 +19,7 @@ ul { margin: 0 0 0 10px ; padding: 0 ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}MOL Projector
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}MOL Projector
<tr>

@ -17,7 +17,7 @@ ul { margin: 0 0 0 10px ; padding: 0 ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}Molotov Cocktail
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}Molotov Cocktail
<tr>
<td style="padding:0 5px;">

@ -20,7 +20,7 @@ sup { font-size: 75% ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}{{PLAYER_NAME}} Ordnance
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}{{PLAYER_NAME}} Ordnance
{%for ord in OB_ORDNANCE%}
<tr style="border-bottom:1px dotted #e0e0e0;">

@ -14,7 +14,7 @@
font-weight: bold ;
{%if OB_SETUP_WIDTH%} width: {{OB_SETUP_WIDTH}} ; {%endif%}
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}{{OB_SETUP}}
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}{{OB_SETUP}}
</table>

@ -20,7 +20,7 @@ sup { font-size: 75% ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}{{PLAYER_NAME}} Vehicles
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}{{PLAYER_NAME}} Vehicles
{%for veh in OB_VEHICLES%}
<tr style="border-bottom:1px dotted #e0e0e0;">

@ -18,7 +18,7 @@ td.r { text-align: right ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}Panzerfaust
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}Panzerfaust
<tr>

@ -18,7 +18,7 @@ td.r { text-align: right ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}PIAT
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}PIAT
<tr>

@ -18,7 +18,7 @@ td.r { text-align: right ; }
padding: 2px 5px ;
font-weight: bold ;
">
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}" height=15 width=15>&nbsp;{%endif%}Panzerschrek
{%if PLAYER_FLAG%}<img src="{{PLAYER_FLAG}}?height=11">&nbsp;{%endif%}Panzerschrek
<tr>

@ -4,8 +4,10 @@ import os
import json
import re
import zipfile
import io
from flask import jsonify, abort
from flask import request, jsonify, send_file, abort
from PIL import Image
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import DATA_DIR
@ -108,6 +110,30 @@ def _do_get_template_pack( dname ):
@app.route( "/flags/<nat>" )
def get_flag( nat ):
"""Get a flag image."""
# validate the nationality
if not re.search( "^[-a-z]+$", nat ):
abort( 404 )
return app.send_static_file( "images/flags/{}.png".format( nat ) )
fname = "static/images/flags/{}.png".format( nat )
with app.open_resource( fname, "rb" ) as fp:
# load the image
img = Image.open( fp )
# check if we should resize the image
# NOTE: Resizing images in the HTML snippets looks dreadful (presumably
# because VASSAL's HTML engine is so ancient), so we do it ourself :-/
height = request.args.get( "height" )
if height:
height = int( height )
if height > 0:
width = img.size[0] / ( float(img.size[1]) / height )
width = int( width + 0.5 )
img = img.resize( (width,height), Image.ANTIALIAS )
# return the image
buf = io.BytesIO()
img.save( buf, format="PNG" )
buf.seek( 0 )
return send_file( buf, mimetype="image/png" )

Loading…
Cancel
Save