这是一种获取所需结果的简单方法。步骤如下:
首先,使用caption:
获取ImageMagick来告诉您将用于填充文本框并提取该信息的点数
创建一个画布,其宽度是您真正想要的画布的两倍,高度是您真正想要的画布的两倍,并在其中间绘制文本-它势必适合您!
现在,修剪掉文本周围的多余背景,以便有一个绝对最小边界框来包含文本
将结果调整为所需的大小。
#!/bin/bash
# Width, height and text
w=600
h=150
text="KJHGFD"
# Get pointsize ImageMagick thinks is good
pointsize=$(convert -gravity center -background black -fill white -size ${w}x${h} \
-font "Winter Calligraphy.ttf" caption:"$text" -format "%[caption:pointsize]" info:)
echo ImageMagick likes pointsize: $pointsize
# So draw text in that size on larger canvas, trim to bounds of letters and resize to desired size
wb=$((w*2))
hb=$((h*2))
convert -gravity center -fill white -size ${wb}x${hb} xc:black \
-font "Winter Calligraphy.ttf" -pointsize $pointsize -annotate 0 "$text" \
-trim +repage -resize ${w}x${h}\! result.png
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句