【发布时间】:2018-09-12 05:15:20
【问题描述】:
我想将文本创建为位图。该文本被认为是长字符串文本。
所以请告诉我如何从文本创建位图。
我试过这个:
from PIL import Image, ImageFont
img = Image.new('L', (500, 500), color=0)
img_w, img_h = img.size
font = ImageFont.truetype('arial.ttf', 20)
mask = font.getmask('some text related location that is going to write here.'
'this is watermark text', mode='L')
mask_w, mask_h = mask.size
print(mask_w,mask_h)
print(type(mask))
d = Image.core.draw(img.im, 0)
# d = d.rotate(40)
d.draw_bitmap(((img_w - mask_w)/2, (img_h - mask_h)/2), mask, 255)
img = img.rotate(40)
img.show()
img.save('op.jpg')
【问题讨论】:
-
您是否尝试在旋转之前打印图像?
img = img.rotate(40)声明可能是这背后的原因。 -
是的..当然我试过..在旋转文本之前以相同的方式剪切..
-
haptik.ai/tech/… 试试这个链接