text - 如何在 Imagemagick 中为文本添加填充?

标签 text imagemagick padding

我的这张图片宽 500 像素。想要在左侧和右侧的文本中添加一些空白或填充。 我尝试过:

convert source.jpg \
        -size 500x \
        -background blue \
        -fill white \
        -pointsize 32 \
        caption:"Sed felis eros, ornare ut cursus a, imperdiet sit amet purus." \
        +swap \
        -append \
        output.jpg

结果:

enter image description here

然后尝试使用 splice,它添加了一个蓝色的列:

convert source.jpg \
        -size 500x \
        -background blue \
        -fill white \
        -pointsize 32 \
        caption:"Sed felis eros, ornare ut cursus a, imperdiet sit amet purus." \
        -splice 10x10 \
        +swap \
        -append \
        output.jpg

结果:

enter image description here

如何仅在蓝色文本框周围添加填充?

最佳答案

也许-extent-gravity选项?下面的例子(用颜色来说明)

convert \( \
       -size 500x \
       -background blue \
       -fill white \
       -pointsize 32 \
       caption:"Sed felis eros, ornare ut cursus a, imperdiet sit amet purus." \
   \) \
   source.jpg \
   -append \
   -background green \
   -gravity Center \
   -extent 520x \
   output.jpg

How to add padding to text

或者只是文本...

convert \( \
        -size 480x \
        -background blue \
        -fill white \
        -pointsize 32 \
        caption:"Sed felis eros, ornare ut cursus a, imperdiet sit amet purus." \
        -gravity Center \
        -extent 500x \
    \) \
    source.jpg \
    -append \
    output.jpg

Just the text part

根据评论进行编辑

要包含上/下和左/右内边距,那么您不妨使用 -border

 convert -size 480x \
         -background blue \
         -fill white \
         -pointsize 32 \
         caption:"Sed feels eros, ornate ut cursus a, imperdiet sit amet purus." \
         -bordercolor green \
         -border 10x20 \
         output.png

Top & bottom padding

关于text - 如何在 Imagemagick 中为文本添加填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37218844/

相关文章:

C++ 不 append 到文本文件

JavaScript改变指定值的输入字段的背景颜色

node.js - 如何将图像缓冲区数据传递给 gm in() GraphicsMagick

c - 是否需要保留填充位?

带填充的 CSS 跨度换行

C++ 编译器对齐 - 仅字符无填充

Python:打印到 html 时如何保持从 txt 文件读取的中断

python - 在外部文本文件中查找字符串所在的行号

c++ - 在 mfc 中调整(通过拖动)对话框窗口大小时,内存资源使用率上升

php - ImageMagick 和 mogrify 裁剪