Spaces:
Runtime error
Runtime error
File size: 704 Bytes
50aa037 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from PIL import Image, ImageDraw, ImageFont
class Renderer:
def __init__(self, fontpath='unifont.ttf'):
# load the font
self.font = ImageFont.truetype(fontpath, 32)
def render_image(self, corrupted, original):
# create a new image with height slightly larger than the font size
text_length_px = self.font.getsize(corrupted + ' ' + original)[0]
img = Image.new('RGB', (text_length_px + 20, 40), color='white')
# create a drawing context
draw = ImageDraw.Draw(img)
# draw the text
draw.text((10, 0), corrupted + ' ' +
original, font=self.font, fill='black')
# return the image
return img
|