I am trying to draw certain unicode characters on and image using python (PIL to be precise).
Using the following code I can generate the images with a white background:
('entity_code' is passed in to the method)
size = self.font.getsize(entity_code)
im = Image.new("RGBA", size, (255,255,255))
draw = ImageDraw.Draw(im)
draw.text((0,6), entity_code, font=self.font, fill=(0,0,0))
del draw
img_buffer = StringIO()
im.save(img_buffer, format="PNG")
I tried the following:
('entity_code' is passed in to the method)
img = Image.new('RGBA',(100, 100))
draw = ImageDraw.Draw(img)
draw.text((0,6), entity_code, fill=(0,0,0), font=self.font)
img_buffer = StringIO()
img.save(img_buffer, 'GIF', transparency=0)
This however fails to draw the unicode character. It looks like I end up with an empty transparent image :(
What am I missing here? Is there a better way to draw text on a transparent image in python?