我试图在现有图像的中心绘制文本,但无法达到预期的结果:
这是到目前为止我已经尝试过的
convert src-image.png -gravity center -pointsize 144 -fill red -annotate -50 'REGISTERED' temp2.png
我能够以一定角度在中心实现文本,但我的要求是为多个图像尺寸提供这样的文本,这些尺寸可能会有所不同。
Here是我尝试过但无法获得准确工作命令的参考之一。 请让我知道如何针对可变图像尺寸实现以下结果。 预期图像:
我能够使用链接答案中的以下 shell 脚本参考来实现所需的结果:
#!/bin/bash
# Width, height and text
w=$1
h=$2
text=$3
source_file=$4
target_file=$5
# Get pointsize ImageMagick thinks is good
pointsize=$(convert -gravity center -size ${w}x${h} 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 $source_file -gravity center -fill white -size ${wb}x${hb} -pointsize $pointsize -annotate -45 "$text" -trim +repage -resize ${w}x${h}\! $target_file
来电者
./paint.sh 5237 7852 "REGISTERED" input-image.jpeg result.jpg