Pythonを使用して特定のUnicode文字と画像を描画しようとしています(正確にはPIL)。
次のコードを使用すると、背景が白い画像を生成できます。
('entity_code' はメソッドに渡されます)
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)
ただし、これはユニコード文字の描画に失敗します。空の透明な画像になってしまうようです:(
ここで何が欠けていますか?Pythonで透明な画像にテキストを描画するより良い方法はありますか?