相关疑难解决方法(0)

Python PIL:字体粗细和样式

在我的电脑上,我只有一个用于Ubuntu Condensed字体的文件.即:

/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-C.ttf 
Run Code Online (Sandbox Code Playgroud)

但是,在LibreOffice中,我可以将此字体设为粗体和斜体: 在此输入图像描述

Ubuntu字体测试器网页上,我还可以为Ubuntu Condensed系列设置不同的字体粗细(即常规和粗体)和不同的字体样式(即正常和斜体).在CSS中,这可能转化为:

/* CSS for bold and italic Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: italic;
font-weight: 700;
Run Code Online (Sandbox Code Playgroud)

要么:

/* CSS for regular and normal Ubuntu Condensed font */
font-family: Ubuntu Condensed;
font-style: normal;
font-weight: 400;
Run Code Online (Sandbox Code Playgroud)

但是,当谈到Python的PIL/Pillow时,我找不到ImageFont中任何可以修改字体样式和/或重量的工作选项,除了ImageFont.truetype()函数加载不同的字体文件.

对于"常规"Ubuntu字体(不是Condensed),我可以加载四个单独文件中的一个,以在Python中获得普通,粗体,斜体和粗体+斜体样式:

/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-RI.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf
/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf
Run Code Online (Sandbox Code Playgroud)

但不适用于Ubuntu Condensed.

所以问题是,是否可以在PIL/Pillow中使用粗体和/或斜体Ubuntu Condensed字体绘制图像?或者至少可以生成四个Ubuntu Condensed文件,以便它可以像Python中的Ubuntu字体一样使用?

python fonts truetype python-imaging-library pillow

5
推荐指数
1
解决办法
945
查看次数

标签 统计

fonts ×1

pillow ×1

python ×1

python-imaging-library ×1

truetype ×1