从命令行将字母表中的字母转储到一系列 Png 中?
Dump the letters of the alphabet to a series of Pngs from the command line?
我想创建一堆 PNG,每个字母对应一个字母。
如何在 mac/linux 上从命令行执行此操作?
以下脚本会将字母转储为一系列 PNG。 convert
实用程序需要在您的系统上安装 imageMagick 和 GhostScript。
例如
# 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 ''" $TEMPLATE $PREFIX.png
}
# Generate images
for x in {A..Z}
do
createImage $x
done
rm -f $TEMPLATE
您可以使用 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>\)@'$l'@' a.svg | convert - $l.png; done
你会得到所有的字母
我想创建一堆 PNG,每个字母对应一个字母。
如何在 mac/linux 上从命令行执行此操作?
以下脚本会将字母转储为一系列 PNG。 convert
实用程序需要在您的系统上安装 imageMagick 和 GhostScript。
例如
# 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 ''" $TEMPLATE $PREFIX.png
}
# Generate images
for x in {A..Z}
do
createImage $x
done
rm -f $TEMPLATE
您可以使用 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>\)@'$l'@' a.svg | convert - $l.png; done
你会得到所有的字母