在ubuntu下生成类名的图片时,即文字转图片,报错:convert : unable to read font
脚本:make_label.py:
import os
l = ["yieldsign"]
for word in l:
os.system("convert -fill black -background white -bordercolor white -border 4 -font futura-normal -pointsize 18 label:\"%s\" \"%s.png\""%(word, word))
原因是没有-font后面的futural-normal, 用全路径就可以了。这里为了输出中文,添加了utf-8编码:
# -*- coding: utf-8 -*-
import os
l=["rabbit", "fish", "deer", "tiger", "cat", "兔子"]
for word in l:
os.system("convert -fill black -background white -bordercolor white -border 4 -font /usr/share/fonts/truetype/arphic/ukai.ttc -pointsize 18 label:\"%s\" \"%s.png\""%(word, word))
自己到系统的字体目录找一个可用的中文字体,不一定是下面这个的:
/usr/share/fonts/truetype/arphic/ukai.ttc