我将尝试使用Python(准确来说是PIL)在图像上绘制特定的Unicode字符。
使用以下代码可以生成带有白色背景的图像:
('entity_code'被传递到该方法中)
然而,这无法绘制Unicode字符。看起来我最终得到了一个空的透明图像:(
我错过了什么?有没有更好的方法在Python中绘制透明图像上的文本?
size = self.font.getsize(entity_code)
im = Image.new("RGBA", size, (255,255,255))
draw = ImageDraw.Draw(im)
draw.text((0,6), entity_code, font=self.font, fill=(0,0,0))
del draw
img_buffer = StringIO()
im.save(img_buffer, format="PNG")
我尝试了以下方法:
('entity_code'作为参数传入该方法)
img = Image.new('RGBA',(100, 100))
draw = ImageDraw.Draw(img)
draw.text((0,6), entity_code, fill=(0,0,0), font=self.font)
img_buffer = StringIO()
img.save(img_buffer, 'GIF', transparency=0)
然而,这无法绘制Unicode字符。看起来我最终得到了一个空的透明图像:(
我错过了什么?有没有更好的方法在Python中绘制透明图像上的文本?