开发者

Unicode problem with text in images in Python

开发者 https://www.devze.com 2023-03-24 14:34 出处:网络
I need to create in python an image with unicode chars like △ ▽ ◆ ◇ ◎ ◯ but I don\'t find the way.. I wonder how firefox or other programs print them well with the same font I use even.. this is

I need to create in python an image with unicode chars like △ ▽ ◆ ◇ ◎ ◯ but I don't find the way.. I wonder how firefox or other programs print them well with the same font I use even.. this is my开发者_如何学Python code

#!/usr/local/bin/python
# -*- coding: utf-8 -*-

import Image, ImageDraw, ImageFont

chars = u'△ 0x25b3, ▽ 0x25bd, ◅ 0x25c5, ◆ 0x25c6, ◇ 0x25c7, ◎ 0x25ce, ◯ 0x25ef'

img  = Image.new('L', (500,50), 255)
draw = ImageDraw.Draw(img)
draw.text((0,0), chars, font=ImageFont.truetype('cour.ttf', 11))
img.save(r'D:\\test.jpg')


You need to pick a font which contains those glyph's. Most likely the font face you are using, cour.ttf, does not contain the glyphs you are trying to write. You could try cyberbit.ttf.

0

精彩评论

暂无评论...
验证码 换一张
取 消