发布于2021-01-17 16:47 阅读(470) 评论(0) 点赞(22) 收藏(2)
0
1
2
3
4
5
6
如何渲染边框不直的文本,就像第二个图像一样?(两个图像的字体不同,但是边框的呈现方式值得关注。)
我的初始代码是
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")
实现此效果的一种简单方法是使用“位移函数”(X(x,y),Y(x,y)),该函数将每个像素移动到附近的位置。此功能应平滑,幅度小且不规则。例如可以通过三角函数与不可数周期的组合来获得。
您将必须使用双线性插值来实现重采样功能,以实现高质量。
0
1
2
3
4
5
作者:黑洞官方问答小能手
链接: https://www.pythonheidong.com/blog/article/777279/0c390339dabfe6e3c1ad/
来源: python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系z452as@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!