Export to GitHub

event-badge-generator - HomePage.wiki


History

This script was initially created to generate event badges for Proto.in 2007 SE (http://www.proto.in/proto2007se/). We had a template and a list of names and used the script to create the badges.

While discussing this script at a lightning talk at Barcamp Bangalore 4, Brad Allen from the Dallas Python User Group suggested releasing the script so that it can be used for other events. Therefore this script is being released under the MIT License.

See badges created with this script being used at the event

Download and Install

The script is distributed as a zip archive. Download and unzip the archive to get the script and associated files. Running the script requires Python 2.4 and Python Imaging Library.

If you want the absolute latest version of the script, you can check it out of the svn repository by heading over to the source tab

Running the script

To generate the badges, you need to execute the createBadges.py file

The script will take the template badge in badge_template.png and the list of name,company pairs (separated by tabs) in people.csv and will generate badges for each person. The script will create a directory called people and put the final badge images there.

To understand the script, look at how the main code uses the classes and methods.

Modifying the script

  • By default, the script will read from people.csv and put the output into people/ directory. To read from another file, pass the name (without the .csv) on the command line. The script will read from that file and output the badges to a directory with that name. You can pass multiple such filenames on the command line.

  • By default, the script will create a double sided badge. This is two badge images that can be folded down the center to make it two sided. The reason for this is that even if the badge twists around when worn, it would still be readable. To generate a single sided badge, set the doubleSided parameter to False when calling the save() method.

  • By default, the script will convert the company name into Title Case. If you do not want this to happen, prepend an asterisk (*) to the company name.

  • The badge template file is passed as a parameter to the constructor of the BadgeImage class

  • Font names, sizes, colours and locations are hardcoded at the moment. A future version will parametrise them. For now, you'll need to delve into the code to change these values. Here are some pointers:

    • Trebucbd.ttf is MS Trebuchet Bold. Change this if you want some other font. If you are using a non-truetype font, you'll need to change the ImageFont.truetype call. PIL supports various font formats. See http://www.pythonware.com/library/pil/handbook/imagefont.htm for help on how to use other font formats.
    • The default font size for person name is 45. This is passed as the first parameter to the getFitSize function. If you want some other font size, change this parameter. Note that the script will automatically scale down the font size if the text does not fit on the badge.
    • The default font size for company name is 26. Again look for the first parameter to the getFitSize function
    • The text colour is passed as a parameter to the drawCenteredText function. This is the second element of the (font, colour) tuple parameter.
    • The location for writing the text is stored in variable pos for the company name and in linepos, linepos1 and linepos2 for the person name. linepos is used if the whole name fits on one line. If the name is split between two lines, linepos1 and linepos2 are used.