Skip to content

Commit

Permalink
Using one font and style of writing for showName
Browse files Browse the repository at this point in the history
Normalize function is now the only one required for the text of the
show name.
  • Loading branch information
itstombellis committed Nov 28, 2016
1 parent 2a2ec5c commit c5ec5b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 57 deletions.
Binary file added Raleway-SemiBold.ttf
Binary file not shown.
82 changes: 25 additions & 57 deletions ShowImageCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,31 @@ def applyBrand(showName, outputName, branding):
overlay = Image.open(colouredBarsPath + brandingOverlay)
img.paste(overlay, (0, 0), overlay)

# First line formatting
# ShowName formatting
log("DEBUG", "Formatting the first line.", showID)
firstLineText, otherLines = normalize(showName)
firstLineFontSize = 85
# firstLineFont = ImageFont.truetype(<font-file>, <font-size>)
firstLineFont = ImageFont.truetype("Raleway-Bold.ttf", firstLineFontSize)
normalizedText = normalize(showName)
text = 65
# textFont = ImageFont.truetype(<font-file>, <font-size>)
textFont = ImageFont.truetype("Raleway-Bold.ttf", text)

draw = ImageDraw.Draw(img)
w, h = draw.textsize(firstLineText, firstLineFont)
firstLineHeight = 210
w, h = draw.textsize(normalizedText, textFont)
textLineHeight = 205

# draw.text((x, y),"Sample Text",(r,g,b))
draw.text(((800-w)/2, firstLineHeight),firstLineText,(255,255,255),firstLineFont, align='center')

# Other Lines Show Text formatting
log("DEBUG", "Formatting further lines.", showID)
otherLinesTextSize = 50
# firstLineFont = ImageFont.truetype(<font-file>, <font-size>)
otherLinesFont = ImageFont.truetype("Raleway-LightItalic.ttf", otherLinesTextSize)

draw = ImageDraw.Draw(img)
w, h = draw.textsize(otherLines, otherLinesFont)
otherLinesTextHeight = 300

# draw.text((x, y),"Sample Text",(r,g,b))
draw.text(((800-w)/2, otherLinesTextHeight), otherLines,(255,255,255),otherLinesFont, align='center')
draw.text(((800-w)/2, textLineHeight),normalizedText,(255,255,255),textFont, align='center')

# website URY formatting
log("DBEUG", "Applying website branding.", showID)
websiteURL = 'URY.ORG.UK/LIVE \n @URY1350'
websiteFont = ImageFont.truetype("Raleway-SemiBoldItalic.ttf", otherLinesTextSize)
websiteTextSize = 50
websiteFont = ImageFont.truetype("Raleway-SemiBoldItalic.ttf", websiteTextSize)
draw = ImageDraw.Draw(img)
w, h = draw.textsize(websiteURL, otherLinesFont)
w, h = draw.textsize(websiteURL, websiteFont)
websiteURLHeight = 510

# draw.text((x, y),"Sample Text",(r,g,b))
draw.text(((800-w)/2, websiteURLHeight), websiteURL,(255,255,255),otherLinesFont, align='center')
draw.text(((800-w)/2, websiteURLHeight), websiteURL,(255,255,255),websiteFont, align='center')

# Saves the image as the output name in a subfolder ShowImages
log("DEBUG", "Saving the final image.", showID)
Expand Down Expand Up @@ -167,41 +155,21 @@ def stripPrefix(showName):
def normalize(input):
log("DEBUG", "Running normalize() function.", showID)
words = input.split(" ")
maxFirstLineLength = 13
firstLine = ''
otherLinesList = []
firstLineFull = False
maxLineLength = 17
maxNumberOfLines = 0 #TODO needs to be implemented.
LinesList = []

for word in words:
if firstLineFull == False:
if (len(word) > maxFirstLineLength) and (len(firstLine) < maxFirstLineLength) and (len(firstLine) > 0):
firstLineFull = True
otherLinesList = dealWithOtherLines(otherLinesList, word)
elif (len(word) > maxFirstLineLength) and (len(firstLine) < maxFirstLineLength):
log("DCM", word +" is too long for first line of image.", showID)
break
elif len(firstLine + word) <= maxFirstLineLength:
firstLine += str(word) + ' '
else:
firstLineFull = True
otherLinesList = dealWithOtherLines(otherLinesList, word)
if len(word) > maxLineLength:
log("DCM", "Word too long for image.", showID, "Within function normalize().")
raise Exception
elif len(LinesList) > 0 and (len(LinesList[-1]) + len(word) < maxLineLength):
LinesList[-1] += " " + word
else:
otherLinesList = dealWithOtherLines(otherLinesList, word)
otherLines = "".join(item + "\n" for item in otherLinesList)
return firstLine, otherLines


def dealWithOtherLines(otherLinesList, word):
log("DEBUG", "Running otherLinesList() function.", showID)
maxOtherLinesLength = 22
if len(word) > maxOtherLinesLength:
log("DCM", "Word too long for image.", showID, "Within function dealWithOtherLines().")
raise Exception
elif len(otherLinesList) > 0 and (len(otherLinesList[-1]) + len(word) < maxOtherLinesLength):
otherLinesList[-1] += " " + word
else:
otherLinesList.append(word)
return otherLinesList
LinesList.append(word)

normalizedText = "".join(item + "\n" for item in LinesList)
return str(normalizedText)


def log(typeM="DEBUG", message="NONE", showNum="NULL", errorMessage="No exception error message."):
Expand All @@ -225,10 +193,10 @@ def log(typeM="DEBUG", message="NONE", showNum="NULL", errorMessage="No exceptio
ShowsDict = getShows()

for key in ShowsDict:

showName = ShowsDict[key]
showID = str(key)
branding = 'OB'

applyBrand(showName, showID, branding)

log("DEBUG", "Program Complete!")

0 comments on commit c5ec5b1

Please sign in to comment.