文字を描く

2017/01/24

Python2.7.10, PIL1.1.7

from PIL import Image, ImageDraw, ImageFont

im = Image.new('RGB',(200,50),(255,255,255))
draw = ImageDraw.Draw(im)
font_path = r'C:\Windows\Fonts\msgothic.ttc'
font_size = 16
font = ImageFont.truetype(font_path,font_size)
pos = (5,5)
text = 'Hello World'
color = (0,0,0)
draw.text(pos,text,color,font)
im.show()


白縁をするには、四方にちょっとずつずらして文字を書く

text = 'テキスト'
font = ImageFont.truetype(font_path,font_size)
hasEdge = True
font_color = (0,0,0)
edge_color = (255,255,255)

im = Image.open(fp)
draw = ImageDraw.Draw(im)
#edge
draw.text((x-1, y-1), text, edge_color,font)
draw.text((x+1, y-1), text, edge_color,font)
draw.text((x-1, y+1), text, edge_color,font)
draw.text((x+1, y+1), text, edge_color,font)
#text
draw.text((x,y),text,font_color,font)

#im.save(save_fp)