【发布时间】:2020-06-24 06:13:54
【问题描述】:
如何使我的文本呈现不直的边框,就像第二张图片一样? (两张图的字体不同,但边框的渲染方式值得关注。)
我的初始代码是
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from random import seed
from random import randint
import numpy as np
import os.path
#Returns the text size in terms of width and height.
def getSize(txt, font):
testImg = Image.new('RGB', (1, 1))
testDraw = ImageDraw.Draw(testImg)
return testDraw.textsize(txt, font)
text = 'lemper'
fontname = 'arial.ttf'
fontsize= 25
font = ImageFont.truetype(fontname, fontsize)
width, height = getSize(text, font)
#Creates an image with white background of constant size.
img = Image.new('RGB', (100, 100), 'white')
d = ImageDraw.Draw( img)
d.text(get_xy_coordinates(text, font), text, fill='black', font=font)
img.save("text_images/1.png")
【问题讨论】:
-
使用您更喜欢的设计的另一种字体。字体之间的差异不是“使用另一种方式呈现它”的情况。实际的设计是不同的。
-
@usr2564301:我认为 OP 不是这个意思。她只是说字体无关紧要。
标签: python python-3.x image image-processing noise