从命令行将字母表中的字母转储到一系列Png中?

时间:2016-01-29 19:22:02

标签: bash command-line-interface

我想创建一堆PNG,每个字母对应一个字母。

如何从mac / linux上的命令行执行此操作?

2 个答案:

答案 0 :(得分:2)

您可以使用 Inkscape 创建字母图像,并设置您想要的任何样式和颜色。 假设您使用字母A创建一个并将其另存为a.svg 然后找到A的位置,例如

style="font-size:72px;fill:#8b0000">A</tspan></text>

并将其替换为循环

for l in {A..Z}; do sed 's@\(#8b0000">\)\(A\)\(</tspan></text>\)@\1'$l'\3@' a.svg | convert - $l.png; done

你将收到所有的信件

enter image description here

答案 1 :(得分:1)

以下脚本会将字母表的字母转储到一系列PNG中。它需要在您的系统上为convert实用程序安装imageMagick和GhostScript。

e.g。

# creates the letters A.png -> Z.png in the current folder
dump_alphabet_as_pngs.sh   

# creates the files test_A.png -> test_Z.png in the current folder, 
# with a red font named "AvantGarde-Book"
dump_alphabet_as_pngs.sh test_ red AvantGarde-Book

dump_alphabet_as_pngs.sh

# Create image for template
TEMPLATE=/tmp/_template.png
convert -size 80x80 xc:white $TEMPLATE

# Setup defaults
PREFIX=${1:-''}
COLOR=${2:-'red'}
FONT=${3:-'helvetica'}
SIZE=${4:-75}

# Note that the following will show you fonts you can use: 'convert -list font |grep Font:'

function createImage()
{
  convert -font $FONT -fill $COLOR -pointsize $SIZE -draw "text 15,70 '$1'" $TEMPLATE $PREFIX$1.png
}

# Generate images
for x in {A..Z}
do
  createImage $x
done

rm -f $TEMPLATE

enter image description here