【问题标题】:Center text vertically but not horizontally in specified box imagemagick在指定的框中垂直居中文本但不水平居中 imagemagick
【发布时间】:2019-01-03 17:28:39
【问题描述】:

我正在尝试从文本生成图像。要求是:文本左对齐,垂直居中,尽可能大,最大。分辨率 1920x1080。

这就是我所拥有的:

convert -background white -fill black \
-font "fonts/DejaVuSansMono.ttf" \
-size 1920x1080 label:'Text \nloooooooooooooooooooooooooong text\nand another' \
-gravity West image.png

它工作得很好,但它不会垂直居中。

看起来像这样: https://imgur.com/rJLxJO2.png

但我希望它看起来像这样:https://imgur.com/IVrydty.png

我可以使用 -size x1080 并使用第二个命令将该图像放入空白图像的中心,但这并不能确保它不会太宽。

【问题讨论】:

    标签: bash imagemagick image-manipulation imagemagick-convert


    【解决方案1】:

    在创建标签之前尝试设置重力......

    convert -background white -fill black -size 1920x1080 \
       -gravity west \
       label:'Text \nloooooooooooooooooooooooooong text\nand another' \
       image.png
    

    编辑添加:当设置应该影响特定操作时,几乎在 ImageMagick 的所有情况下,设置都应该先于操作。 IM 版本 6 在这方面有些宽容,但与您的示例一样,命令的顺序通常很重要。 IM 版本 7 更加严格。

    【讨论】:

    • 谢谢,这是一种问题,当有人立即知道答案时,但我会花几天时间找出答案。它是如此简单。惊人的。再次感谢。
    猜你喜欢
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2020-04-06
    • 2012-03-14
    • 2017-06-28
    • 1970-01-01
    相关资源
    最近更新 更多