Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed conflict from kausikram merge

  • Loading branch information...
commit 43bedd0cf866afa1a285ed7796cfc7e7b9d8aeb7 2 parents 706ed9c + 1a7d40d
Silver Stripe Software authored
Showing with 27 additions and 10 deletions.
  1. +27 −10 createBadges.py
View
37 createBadges.py
@@ -25,8 +25,18 @@
#
from PIL import Image, ImageDraw, ImageFont
+import os
from csvimport import CsvReader
+#####################################################
+######## User Defined Values ########################
+#####################################################
+NAME_COLOR = "#ffffff"
+COMPANY_COLOR = "#ff2b06"
+ID_COLOR = "#ffffff"
+FOLD_COLOR = "#000000"
+
+
class BadgeImage(object):
def __init__(self, filename):
self.img = Image.open(filename)
@@ -56,36 +66,41 @@ def drawPerson(self, name):
linepos = (self.img.size[0]/2, 240)
line1pos = (self.img.size[0]/2, 150)
line2pos = (self.img.size[0]/2, 320)
- size = self.getFitSize(45, name)
if name.find(" ") >= 0:
firstname, rest = name.split(" ", 1)
else:
firstname, rest = (name, "")
- if size < 45 and rest != "":
+ if rest != "":
personFont = ImageFont.truetype("Trebucbd.ttf", self.getFitSize(45, firstname)*300/72)
- self.drawCenteredText(line1pos, firstname, (personFont, "#ffffff"))
+ self.drawCenteredText(line1pos, firstname, (personFont, NAME_COLOR))
personFont = ImageFont.truetype("Trebucbd.ttf", self.getFitSize(45, rest)*300/72)
- self.drawCenteredText(line2pos, rest, (personFont, "#ffffff"))
+ self.drawCenteredText(line2pos, rest, (personFont, NAME_COLOR))
else:
personFont = ImageFont.truetype("Trebucbd.ttf", self.getFitSize(45, name)*300/72)
- self.drawCenteredText(linepos, name, (personFont, "#ffffff"))
+ self.drawCenteredText(linepos, name, (personFont, NAME_COLOR))
def drawCompany(self, name):
pos = (self.img.size[0]/2, 500)
font = ImageFont.truetype("Trebucbd.ttf", self.getFitSize(26, name)*300/72)
- self.drawCenteredText(pos, name, (font, "#0099ff"))
+ self.drawCenteredText(pos, name, (font, COMPANY_COLOR))
def drawId(self, id):
pos = (50, 50)
font = ImageFont.truetype("Trebucbd.ttf", 8*300/72)
- self.drawCenteredText(pos, id, (font, "#ffffff"))
+ self.drawCenteredText(pos, id, (font, ID_COLOR))
+
- def save(self, filename):
- newimg = Image.new("RGB", (self.img.size[0]*2+20, self.img.size[1]), "#000000")
+ def save(self, filename, doubleSided=False):
+ if not doubleSided:
+ self.img.save(filename)
+ return
+
+ newimg = Image.new("RGB", (self.img.size[0]*2+20, self.img.size[1]), FOLD_COLOR)
newimg.paste(self.img, (0,0))
newimg.paste(self.img, (self.img.size[0]+20,0))
newimg.save(filename)
+
class DataFileReader(object):
def __init__(self, filename):
fp = open(filename)
@@ -125,13 +140,15 @@ def getData(self):
count = 0
for filename in filenames:
reader = DataFileReader(filename + ".csv")
+ if not os.path.exists(filename):
+ os.makedirs(filename)
for id, name, company in reader.getData():
print id, name, company
badge = BadgeImage("badge_template.png")
badge.drawPerson(name)
badge.drawCompany(company)
badge.drawId(id)
- badge.save(filename + "\\" + filename + "_badge_" + str(id) + ".png")
+ badge.save(os.path.join(filename, filename + "_badge_" + str(id) + ".png"))
count += 1
print "\n%d badges created" % (count)
Please sign in to comment.
Something went wrong with that request. Please try again.