I want to create a jpg or any other image format files for chinese characters, how do i do it?
My input textfile (in utf8) looks like this:
阿贝•斯兰尼\t是\t美国人
Reading it is simple, i could simply do codecs.open('intext.txt','r','utf8).read().strip().split('\t')
but how can I output an image file that looks like this:
Eventually, the whole jpg might look like this:
So the exact questions are:
PIL (the Python Imaging Library) can both draw lines and unicode text to images, using the ImageDraw module. For your text to be printed correctly, you'll have to ensure that you've got a unicode string (not utf-8 encoded) and a font which contains the characters you want to display.
image = Image.new('RGB', (xsize, ysize))
To get a draw instance for that image:
draw = ImageDraw.Draw(image)
To draw text:
draw.text((xpos,ypos), mytext, font=ImageFont.truetype('myfont.ttf', 11))
To draw a line:
draw.line((startx,starty, endx,endy), fill=128)
To draw an arc:
draw.arc((startx,starty, endx,endy), startangle, endangle)