用 PIL 绘制粗体/斜体文本?
如何用PIL绘制粗体/斜体文本? ImageFont.truetype(file, size) 有一个仅指定字体大小的选项。
How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用字体的粗体/斜体版本
Use the bold/italic version of the font
到目前为止,还没有粗体功能作为参数,但您可以通过向具有相同颜色的文本的文本添加笔划来轻松解决。下一个代码详细说明如何使用笔画,这将是有意义的粗体字体
There is no bold features as parameter till now but easily you can solve by add stroke to the text with same color of text. it will make sense as bold font next code elaborate how to use stroke
如果(无论出于何种原因)您没有单独的粗体版本的字体,则将字体设置为粗体的一个相当老套的解决方案是多次打印相同的文本并稍微偏移。
A rather hacky solution to make a font bold if (for whatever reason) you don't have a separate bold version of the font is to print the same text several times with a slight offset.
许多字体使用不同的 TTF 文件作为粗体/斜体版本,所以我想如果您只指定该文件它就可以工作。
Many fonts use different TTF files for their bold/italic versions, so I'd imagine if you just specify that file it would work.
嗯,这是我的第一条评论。开始了。
我会尽力澄清程序。起初我所做的是像这样使用字体的“名称”,
但只得到了一些这样的错误:
然后我记得有时字体有其他“名称”或“文件名”,所以,我所做的是转到字体文件夹,然后打开Arial字体,其中显示了所有样式,例如negrita(粗体],cursiva(斜体)等。
右键单击“negrita”样式,选择“属性”,然后出现该字体的“真实姓名” 就我而言
,名称是“ariblk”
然后,最后,
我知道这篇文章已经过时了,但今天帮助我找到了解决方案,所以我希望对任何人都有帮助
。
Well, this is my first comment. Here we go.
I'll try to clarify the procedure. At first What I did was use the "name" of the font like this
but only got some errors like this:
Then I remembered that sometimes fonts has other "names" or "filenames", so, what I did was going to fonts folder, then opened the Arial Font wich displayed all the styles like negrita (bold], cursiva(italic), etc.
Did a right click on the "negrita" style, selected "properties" and then there was the "real name" of the font.
In my case, the name was "ariblk"
Then, finally, just used the name like this.
I know this post is old, but today helped me to get to the solution. So I hope to help anybody.
=)
参考此处的其他答案,我对 Arial 粗体变体的名称的搜索产生了以下内容(arialbd.ttf):
['C:\WINDOWS\Fonts\arial.ttf', 'C:\WINDOWS\Fonts\ arialbd.ttf'、'C:\WINDOWS\Fonts\arialbi.ttf'、'C:\WINDOWS\Fonts\ariali.ttf'、'C:\Windows\Fonts\arial.ttf'、'C:\Windows\字体\arialbd.ttf', 'C:\Windows\Fonts\arialbi.ttf', 'C:\Windows\Fonts\ariali.ttf'] (
With reference to the other answers here, my search for the name for the bold variant of Arial produced the following (arialbd.ttf):
['C:\WINDOWS\Fonts\arial.ttf', 'C:\WINDOWS\Fonts\arialbd.ttf', 'C:\WINDOWS\Fonts\arialbi.ttf', 'C:\WINDOWS\Fonts\ariali.ttf', 'C:\Windows\Fonts\arial.ttf', 'C:\Windows\Fonts\arialbd.ttf', 'C:\Windows\Fonts\arialbi.ttf', 'C:\Windows\Fonts\ariali.ttf'] (