yon*_*ron 5 png text imagemagick
我需要获取一个单词列表并为每个单词创建一个具有透明背景的 PNG 文件。
\n\n我\xe2\x80\x99d 喜欢我的脚本允许调整前景的不透明度,但我也可以在图像导入 Matlab 后这样做。
\n\n我想这可以通过 ImageMagick 实现,并且已将其安装在我的 Mac 上。如果有人能给我一行 I\xe2\x80\x99d 需要在 Perl 或 Python 中将一个单词转换为 PNG(该单词也可以是文件名),我可能可以弄清楚其余的脚本。
\n我发现这适用于你的问题:
convert -size 560x85 xc:transparent -font Palatino-Bold -pointsize 72 -fill black -draw "text 20,55 'Linux and Life'" linuxandlife.png
Run Code Online (Sandbox Code Playgroud)
输出:
Matplotlib(更广为人知的名称是 pylab)非常适合此任务。假设安装了 ImageMagick,这个脚本应该可以工作。(在Ubuntu 9.10上测试)
import pylab as py, os
W = ['cat','dog','mouse']
for word in W:
py.clf()
ax = py.axes(alpha=1.0)
py.text(0,.5,word)
py.axis('off')
py.savefig("%s.png"%word)
os.system('convert -trim %s.png %s.png' % (word,word))
Run Code Online (Sandbox Code Playgroud)
这会在我的系统上创建三个文件dog.png
,cat.png
并且mouse.png
全部以透明背景裁剪。