Image Magick - 将文本转换为图像 - 有没有办法将文本居中到图像的中间?

moo*_*ats 11 imagemagick

我有一个简单的文本文件,读取类似"今天是28度"的东西我试图使用imagemagick将其居中到图像的中间.我正在使用的命令就是这个

    `convert -background lightblue -fill blue  -size 165x70 filename.txt image.png`
Run Code Online (Sandbox Code Playgroud)

我尝试使用重力,但由于某种原因,它始终将文本放在图像之外.从我能看到的情况来看,我没有正确使用它.我希望它集中在一起.有什么建议?

Ale*_*sky 20

convert \
    -size 165x70 \
    xc:lightblue \
    -font Bookman-DemiItalic \
    -pointsize 12 \
    -fill blue \
    -gravity center \
    -draw "text 0,0 'It is 28 degrees today'" \
    image.png
Run Code Online (Sandbox Code Playgroud)

如果要从现有文件中提取输入,只需将其输入到draw命令:

convert \
    -size 165x70 \
    xc:lightblue \
    -font Bookman-DemiItalic \
    -pointsize 12 \
    -fill blue \
    -gravity center \
    -draw "text 0,0 '$(cat file.txt)'" \
    image.png
Run Code Online (Sandbox Code Playgroud)