I find a script in a game ,definitly using Microsoft YaHei font .(I replace the font file I find in game folder with my own font file, the script font changes as well )
But after I tried all of size and position parameter ,the render result is always a bit different ,
from PIL import Image, ImageDraw, ImageFont
import numpy as np
i = 12
text = '我是王中王'
font = ImageFont.truetype('mysh.ttf', i)
PIL_image = Image.new('RGB', (100, 100), color=0xffffff)
draw = ImageDraw.Draw(PIL_image)
draw.text((31, 11), text, font=font, fill=10, anchor='mm')
Image.fromarray(np.array(PIL_image)).save('out.png')
This is the piece of code I'm using, by changing the font_size argument ,the most close result is this ,
There are slight differences ,you should be able to locate it .
I realize it could be the position parameter is decimal , but pillow text method seems to truncate decimal positon parameter to integers ,changing the position parameter to decimal makes no difference , how should I do .
from How to render font exactly like what it appears?
No comments:
Post a Comment