I'm using python/PIL to write text on a set of PNG
images. I was able to get the font I wanted, but I'd like to now outline the text in black.
This is what I have: as you can see, if the background is white it is difficult to read.
This is the goal:
Is there a way to accomplish this with PIL? If not, I am open to hearing other suggestions, but no promises because I've already begun a large project in python using PIL.
The section of code that deals with drawing on the images:
for i in range(0,max_frame_int + 1):
writeimg = Image.open("frameinstance" + str(i) + ".png")
newimg = Image.new("RGB", writeimg.size)
newimg.paste(writeimg)
width_image = newimg.size[0]
height_image = newimg.size[1]
draw = ImageDraw.Draw(newimg)
# font = ImageFont.truetype(<font-file>, <font-size>)
for font_size in range(50, 0, -1):
font = ImageFont.truetype("impact.ttf", font_size)
if font.getsize(meme_text)[0] <= width_image:
break
else:
print('no fonts fit!')
# draw.text((x, y),"Sample Text",(r,g,b))
draw.text((int(0.05*width_image), int(0.7*height_image)),meme_text,(255,255,255),font=font)
newimg.save("newimg" + str(i) +".png")