[英]PIL draw text without gray outline
使用ImageFont.getmask和ImageFont.getsize方法,我可以創建一個PIL.Image
對象,該對象用硬邊PIL.Image
文本。
from PIL import Image, ImageFont
fnt = ImageFont.truetype('arial.ttf', 50)
text = 'test, test'
img = Image.new('1', fnt.getsize(text))
mask = [x for x in fnt.getmask(text, mode='1')]
img.putdata(mask)
這個PIL.Image
對象( img
)可以用來在您需要的任何地方將文本添加到您的圖像中,如果您需要更多有關此信息,我可以為您構建一個示例。 請記住, img.mode
為'1'
,表示黑白。 每個像素(由img.getpixel
返回)為0或255。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.