Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9532c6c
hide scratch area
YetAnotherMinion Jul 20, 2015
e4e0fdb
downloaded all pictures
YetAnotherMinion Jul 20, 2015
759ca8e
added flags to app
YetAnotherMinion Jul 20, 2015
9e57245
simple image creation works
YetAnotherMinion Jul 20, 2015
b285830
changed app name to use my dev account
YetAnotherMinion Jul 21, 2015
88f2d9f
factored out into class
YetAnotherMinion Jul 21, 2015
6c3edf6
run once was persistant across requests, removed
YetAnotherMinion Jul 21, 2015
a3cb941
moved flag out of the way
YetAnotherMinion Jul 21, 2015
a64d810
factored variable postion fields into final render call
YetAnotherMinion Jul 21, 2015
f63c473
added name text resizing
YetAnotherMinion Jul 21, 2015
a6bb0e3
added codeabbey logo
YetAnotherMinion Jul 21, 2015
d61b252
removed unused code
YetAnotherMinion Jul 21, 2015
82fc94c
moved the username postions
YetAnotherMinion Jul 21, 2015
4974244
added colored text
YetAnotherMinion Jul 21, 2015
109d054
added robots.txt
YetAnotherMinion Jul 21, 2015
3242ba0
removed debugging prints that were clogging logs
YetAnotherMinion Jul 21, 2015
176e83e
added username truncation
YetAnotherMinion Jul 21, 2015
a8a287b
forgot to add peasant image
YetAnotherMinion Jul 21, 2015
ec775e2
factored out userbadge code from main flask app
YetAnotherMinion Jul 21, 2015
5d2310e
Templates with level pictures
RodionGork Jul 21, 2015
47b6244
new images
YetAnotherMinion Jul 21, 2015
99ada45
added a tool to generate default image for each of rank
YetAnotherMinion Jul 21, 2015
82f1ad6
added rank and position
YetAnotherMinion Jul 21, 2015
0fe0319
Merge pull request #4 from RodionGork/master
YetAnotherMinion Jul 21, 2015
8583b8d
updated to use rankNumber in code
YetAnotherMinion Jul 21, 2015
6e366a5
bump app version
YetAnotherMinion Jul 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
*.pyc
*.pyo

static/stubs*
scratch/*

#ignore the pictures and font files
tools/*.png
tools/*.ttf
10 changes: 8 additions & 2 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application: codeabbey-banners
version: 1
application: code-abbey-banner
version: 4
runtime: python27
api_version: 1
threadsafe: yes
Expand All @@ -13,3 +13,9 @@ libraries:
version: "2.6"
- name: markupsafe
version: "0.15"
- name: PIL
version: "1.1.7"

skip_files:
- ^(.*/)?\.git.*$
- ^(.*/)?.*pyc$
Binary file added flags/ad.gif
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 flags/ae.gif
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 flags/af.gif
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 flags/ag.gif
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 flags/ai.gif
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 flags/al.gif
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 flags/am.gif
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 flags/an.gif
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 flags/ao.gif
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 flags/ar.gif
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 flags/as.gif
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 flags/at.gif
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 flags/au.gif
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 flags/aw.gif
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 flags/ax.gif
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 flags/az.gif
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 flags/ba.gif
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 flags/bb.gif
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 flags/bd.gif
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 flags/be.gif
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 flags/bf.gif
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 flags/bg.gif
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 flags/bh.gif
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 flags/bi.gif
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 flags/bj.gif
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 flags/bm.gif
Binary file added flags/bn.gif
Binary file added flags/bo.gif
Binary file added flags/br.gif
Binary file added flags/bs.gif
Binary file added flags/bt.gif
Binary file added flags/bv.gif
Binary file added flags/bw.gif
Binary file added flags/by.gif
Binary file added flags/bz.gif
Binary file added flags/ca.gif
Binary file added flags/cc.gif
Binary file added flags/cd.gif
Binary file added flags/cf.gif
Binary file added flags/cg.gif
Binary file added flags/ch.gif
Binary file added flags/ci.gif
Binary file added flags/ck.gif
Binary file added flags/cl.gif
Binary file added flags/cm.gif
Binary file added flags/cn.gif
Binary file added flags/co.gif
Binary file added flags/cr.gif
Binary file added flags/cu.gif
Binary file added flags/cv.gif
Binary file added flags/cx.gif
Binary file added flags/cy.gif
Binary file added flags/cz.gif
Binary file added flags/de.gif
Binary file added flags/dj.gif
Binary file added flags/dk.gif
Binary file added flags/dm.gif
Binary file added flags/do.gif
Binary file added flags/dz.gif
Binary file added flags/ec.gif
Binary file added flags/ee.gif
Binary file added flags/eg.gif
Binary file added flags/er.gif
Binary file added flags/es.gif
Binary file added flags/et.gif
Binary file added flags/fi.gif
Binary file added flags/fj.gif
Binary file added flags/fk.gif
Binary file added flags/fm.gif
Binary file added flags/fo.gif
Binary file added flags/fr.gif
Binary file added flags/ga.gif
Binary file added flags/gb.gif
Binary file added flags/gd.gif
Binary file added flags/ge.gif
Binary file added flags/gf.gif
Binary file added flags/gh.gif
Binary file added flags/gi.gif
Binary file added flags/gl.gif
Binary file added flags/gm.gif
Binary file added flags/gn.gif
Binary file added flags/gp.gif
Binary file added flags/gq.gif
Binary file added flags/gr.gif
Binary file added flags/gs.gif
Binary file added flags/gt.gif
Binary file added flags/gu.gif
Binary file added flags/gw.gif
Binary file added flags/gy.gif
Binary file added flags/hk.gif
Binary file added flags/hm.gif
Binary file added flags/hn.gif
Binary file added flags/hr.gif
Binary file added flags/ht.gif
Binary file added flags/hu.gif
Binary file added flags/id.gif
Binary file added flags/ie.gif
Binary file added flags/il.gif
Binary file added flags/in.gif
Binary file added flags/io.gif
Binary file added flags/iq.gif
Binary file added flags/ir.gif
Binary file added flags/is.gif
Binary file added flags/it.gif
Binary file added flags/jm.gif
Binary file added flags/jo.gif
Binary file added flags/jp.gif
Binary file added flags/ke.gif
Binary file added flags/kg.gif
Binary file added flags/kh.gif
Binary file added flags/ki.gif
Binary file added flags/km.gif
Binary file added flags/kn.gif
Binary file added flags/kp.gif
Binary file added flags/kr.gif
Binary file added flags/kw.gif
Binary file added flags/ky.gif
Binary file added flags/kz.gif
Binary file added flags/la.gif
Binary file added flags/lb.gif
Binary file added flags/lc.gif
Binary file added flags/li.gif
Binary file added flags/lk.gif
Binary file added flags/lr.gif
Binary file added flags/ls.gif
Binary file added flags/lt.gif
Binary file added flags/lu.gif
Binary file added flags/lv.gif
Binary file added flags/ly.gif
Binary file added flags/ma.gif
Binary file added flags/mc.gif
Binary file added flags/md.gif
Binary file added flags/me.gif
Binary file added flags/mg.gif
Binary file added flags/mh.gif
Binary file added flags/mk.gif
Binary file added flags/ml.gif
Binary file added flags/mm.gif
Binary file added flags/mn.gif
Binary file added flags/mo.gif
Binary file added flags/mp.gif
Binary file added flags/mq.gif
Binary file added flags/mr.gif
Binary file added flags/ms.gif
Binary file added flags/mt.gif
Binary file added flags/mu.gif
Binary file added flags/mv.gif
Binary file added flags/mw.gif
Binary file added flags/mx.gif
Binary file added flags/my.gif
Binary file added flags/mz.gif
Binary file added flags/na.gif
Binary file added flags/nc.gif
Binary file added flags/ne.gif
Binary file added flags/nf.gif
Binary file added flags/ng.gif
Binary file added flags/ni.gif
Binary file added flags/nl.gif
Binary file added flags/no.gif
Binary file added flags/np.gif
Binary file added flags/nr.gif
Binary file added flags/nu.gif
Binary file added flags/nz.gif
Binary file added flags/om.gif
Binary file added flags/pa.gif
Binary file added flags/pe.gif
Binary file added flags/pf.gif
Binary file added flags/pg.gif
Binary file added flags/ph.gif
Binary file added flags/pk.gif
Binary file added flags/pl.gif
Binary file added flags/pm.gif
Binary file added flags/pn.gif
Binary file added flags/pr.gif
Binary file added flags/pt.gif
Binary file added flags/pw.gif
Binary file added flags/py.gif
Binary file added flags/qa.gif
Binary file added flags/re.gif
Binary file added flags/ro.gif
Binary file added flags/rs.gif
Binary file added flags/ru.gif
Binary file added flags/rw.gif
Binary file added flags/sa.gif
Binary file added flags/sb.gif
Binary file added flags/sc.gif
Binary file added flags/sd.gif
Binary file added flags/se.gif
Binary file added flags/sg.gif
Binary file added flags/sh.gif
Binary file added flags/si.gif
Binary file added flags/sj.gif
Binary file added flags/sk.gif
Binary file added flags/sl.gif
Binary file added flags/sm.gif
Binary file added flags/sn.gif
Binary file added flags/so.gif
Binary file added flags/sr.gif
Binary file added flags/st.gif
Binary file added flags/sv.gif
Binary file added flags/sy.gif
Binary file added flags/sz.gif
Binary file added flags/tc.gif
Binary file added flags/td.gif
Binary file added flags/tf.gif
Binary file added flags/tg.gif
Binary file added flags/th.gif
Binary file added flags/tj.gif
Binary file added flags/tk.gif
Binary file added flags/tl.gif
Binary file added flags/tm.gif
Binary file added flags/tn.gif
Binary file added flags/to.gif
Binary file added flags/tr.gif
Binary file added flags/tt.gif
Binary file added flags/tv.gif
Binary file added flags/tw.gif
Binary file added flags/tz.gif
Binary file added flags/ua.gif
Binary file added flags/ug.gif
Binary file added flags/um.gif
Binary file added flags/us.gif
Binary file added flags/uy.gif
Binary file added flags/uz.gif
Binary file added flags/va.gif
Binary file added flags/vc.gif
Binary file added flags/ve.gif
Binary file added flags/vg.gif
Binary file added flags/vi.gif
Binary file added flags/vn.gif
Binary file added flags/vu.gif
Binary file added flags/wf.gif
Binary file added flags/ws.gif
Binary file added flags/ye.gif
Binary file added flags/yt.gif
Binary file added flags/za.gif
Binary file added flags/zm.gif
Binary file added flags/zw.gif
Binary file added fonts/dejavu/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file added fonts/dejavu/DejaVuSans.ttf
Binary file not shown.
Binary file added fonts/dejavu/DejaVuSerifCondensed-BoldItalic.ttf
Binary file not shown.
99 changes: 99 additions & 0 deletions fonts/dejavu/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)

Bitstream Vera Fonts Copyright
------------------------------

Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:

The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.

The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".

This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.

The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.

Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.

Arev Fonts Copyright
------------------------------

Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:

The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.

The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".

This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.

The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.

$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $
3 changes: 3 additions & 0 deletions lib/UserBadge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = '0.1'

from _user_badge import UserBadge, RankCodeAbbey
194 changes: 194 additions & 0 deletions lib/UserBadge/_user_badge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
from PIL import Image, ImageDraw, ImageFont
import cStringIO
import StringIO
import urllib
import urllib2
import json
import string

from random import randint

class RankCodeAbbey(object):
PEASANT = 0
ACOLYTE = 1
BELIEVER = 2
FOLLOWER = 3
PRIEST = 4
FANATIC = 5
DEACON = 6
BISHOP = 7
STARGAZER = 8
THE_DOCTOR = 9
FROST_ENCHANTER = 10
CARDINAL = 11


class UserBadge(object):
def __init__(self, x_size, y_size, rank = 'default'):
self.rank = rank
self.width = x_size
self.height = y_size
#store the colors
self.rank_rgb_color_dict = { RankCodeAbbey.PEASANT: (136, 136, 136),
RankCodeAbbey.ACOLYTE: (68, 255, 68),
RankCodeAbbey.BELIEVER: (0, 221, 221),
RankCodeAbbey.FOLLOWER: (68, 68, 255),
RankCodeAbbey.PRIEST: (221, 0, 221),
RankCodeAbbey.FANATIC: (221, 221, 0),
RankCodeAbbey.DEACON: (255, 153, 17),
RankCodeAbbey.BISHOP: (255, 68, 68),
RankCodeAbbey.STARGAZER: (68, 68, 255),
RankCodeAbbey.THE_DOCTOR: (255, 153, 17),
RankCodeAbbey.FROST_ENCHANTER: (0, 204, 238),
RankCodeAbbey.CARDINAL: (135, 0, 170),
'default': (0, 0, 0)
}

print rank
if RankCodeAbbey.PEASANT <= rank <= RankCodeAbbey.CARDINAL:
background_filename = 'static/rank' + str(rank) + '.png'
else:
background_filename = 'static/default.png'

self.img = Image.open(background_filename)
self.draw = ImageDraw.Draw(self.img)

#leave this stub in for now to create arbitrary size images
if rank == None:
self.img = Image.new("RGB", (x_size, y_size), '#FFFFFF')
self.draw = ImageDraw.Draw(self.img)
#set this to default for use by the other derived fields
self.rank = 'default'


self.padding = 5
#configure square user image
self.tb_size = 50
self.tb_x_offset = self.width - self.tb_size - self.padding
self.tb_y_offset = self.padding

#configure size of flag
self.flag_width = 16
self.flag_height = 11
self.flag_spacing = 5

#configure size available for user name
self.name_x_offset = self.padding
self.username_allowed_width = self.width - self.name_x_offset - self.flag_spacing - self.flag_width - self.padding - self.tb_size - self.padding
self.username_baseline_offset = self.height * 0.35
self.username_height = 35


def AddUserName(self, name, rank = "default"):
#parameters to adjust name location and appearance
name_font_size = 14
try:
name_font_color = self.rank_rgb_color_dict[self.rank]
except KeyError as e:
name_font_color = (0,0,0)

#we are using this font just to test since it looks different
#than system font, so we can know when it is working
unicode_font = ImageFont.truetype("fonts/dejavu/DejaVuSerifCondensed-BoldItalic.ttf", name_font_size)
while True:
#dynamically determine the offset to have a relative placement in image
(predicted_width, predicted_height) = unicode_font.getsize(name)
if(predicted_width > self.username_allowed_width) and name_font_size > 12:
name_font_size -= 1
unicode_font = ImageFont.truetype("fonts/dejavu/DejaVuSerifCondensed-BoldItalic.ttf", name_font_size)
else:
#check for case where we have to truncate

while True:
if(predicted_width > self.username_allowed_width) and len(name) > 0:
(predicted_width, predicted_height) = unicode_font.getsize(name)
#truncate the string by one
name = name[:-1]
else:
break
self.username_width = predicted_width
self.username_height = predicted_height
break

#compute the y offset to keep constant baseline position
self.name_y_offest = max([0, (self.username_baseline_offset - predicted_height)])

self.draw.text((self.name_x_offset, self.name_y_offest), name, font = unicode_font, fill = name_font_color)

def AddCountryFlag(self, country):
iso_country_codes = set(['BD', 'BE', 'BF', 'BG', 'BA', 'BB', 'WF', 'BM', 'BN', 'BO',
'BH', 'BI', 'BJ', 'BT', 'JM', 'BV', 'BW', 'WS', 'BR', 'BS', 'JE', 'BY', 'BZ',
'RU', 'RW', 'RS', 'TL', 'RE', 'TM', 'TJ', 'RO', 'TK', 'GW', 'GU', 'GT', 'GS',
'GR', 'GQ', 'GP', 'JP', 'GY', 'GG', 'GF', 'GE', 'GD', 'GB', 'GA', 'GN', 'GM',
'GL', 'GI', 'GH', 'OM', 'TN', 'JO', 'TA', 'HR', 'HT', 'HU', 'HK', 'HN', 'HM',
'VE', 'PR', 'PW', 'PT', 'KN', 'PY', 'AI', 'PA', 'PF', 'PG', 'PE', 'PK', 'PH',
'PN', 'PL', 'PM', 'ZM', 'EE', 'EG', 'ZA', 'EC', 'IT', 'VN', 'SB', 'ET', 'SO',
'ZW', 'KY', 'ES', 'ER', 'ME', 'MD', 'MG', 'MA', 'MC', 'UZ', 'MM', 'ML', 'MO',
'MN', 'MH', 'MK', 'MU', 'MT', 'MW', 'MV', 'MQ', 'MP', 'MS', 'MR', 'IM', 'UG',
'MY', 'MX', 'IL', 'FR', 'AW', 'SH', 'AX', 'SJ', 'FI', 'FJ', 'FK', 'FM', 'FO',
'NI', 'NL', 'NO', 'NA', 'VU', 'NC', 'NE', 'NF', 'NG', 'NZ', 'NP', 'NR', 'NU',
'CK', 'CI', 'CH', 'CO', 'CN', 'CM', 'CL', 'CC', 'CA', 'CG', 'CF', 'CD', 'CZ',
'CY', 'CX', 'CR', 'CV', 'CU', 'SZ', 'SY', 'KG', 'KE', 'SR', 'KI', 'KH', 'SV',
'KM', 'ST', 'SK', 'KR', 'SI', 'KP', 'KW', 'SN', 'SM', 'SL', 'SC', 'KZ', 'SA',
'SG', 'SE', 'SD', 'DO', 'DM', 'DJ', 'DK', 'VG', 'DE', 'YE', 'DZ', 'US', 'UY',
'YT', 'UM', 'LB', 'LC', 'LA', 'TV', 'TW', 'TT', 'TR', 'LK', 'LI', 'LV', 'TO',
'LT', 'LU', 'LR', 'LS', 'TH', 'TF', 'TG', 'TD', 'TC', 'LY', 'VA', 'AC', 'VC',
'AE', 'AD', 'AG', 'AF', 'IQ', 'VI', 'IS', 'IR', 'AM', 'AL', 'AO', 'AN', 'AQ',
'AS', 'AR', 'AU', 'AT', 'IO', 'IN', 'TZ', 'AZ', 'IE', 'ID', 'UA', 'QA', 'MZ'])
if country in iso_country_codes:
self.flag_name = 'flags/' + country.lower() + '.gif'

def AddNumSolved(self, num_solved = 0):
#error case num solved is ?
text = 'solved: '
if num_solved > 0:
#hold field with to max of 4 chars
text += str(num_solved)[-4:]

unicode_font = ImageFont.truetype("fonts/dejavu/DejaVuSans.ttf", 10)
solved_xo = self.padding
solved_yo = int(self.height * 0.45)
self.draw.text((solved_xo, solved_yo), text, font = unicode_font, fill = (32,32,32))


def AddPosition(self, position):
#error case num solved is ?
text = 'rank: '
if position > 0:
#switch to scientific notation if rank is large enough
if position > 999999:
if(position >= 1e100):
position = ">1e100"
else:
position = "{:.2e}".format(position)
#remove the positive exponent
position = string.replace(position, '+', '')
else:
position = str(position)
#hold field with to max of 4 chars
text += position[-10:]

unicode_font = ImageFont.truetype("fonts/dejavu/DejaVuSans.ttf", 10)
solved_xo = self.padding + 65
solved_yo = int(self.height * 0.45)
self.draw.text((solved_xo, solved_yo), text, font = unicode_font, fill = (32,32,32))



def RenderToBuffer(self):
#render all of variable position boxes here at once
self.flag_x_offset = int(self.name_x_offset + self.username_width + self.flag_spacing)
#Adjust this parameter to vary the spacing of the flag picture from baseline
FLAG_FUDGE_FACTOR = 0.3
#self.draw.line((0, self.username_baseline_offset, self.width, self.username_baseline_offset), fill = (0,0,0))
self.flag_y_offest = max([0, int(self.username_baseline_offset - int(self.username_height * FLAG_FUDGE_FACTOR)- self.flag_height)])


flag_file = Image.open(self.flag_name)
(flag_x,flag_y) = flag_file.size
self.img.paste(flag_file, (self.flag_x_offset, self.flag_y_offest, self.flag_x_offset+flag_x , self.flag_y_offest+flag_y))

#create buffer for output
f = cStringIO.StringIO()
self.img.save(f, "PNG")
return f
Loading