【问题标题】:Imagemagick: how to add border with text just below the image?Imagemagick:如何在图像下方添加带有文本的边框?
【发布时间】:2017-12-30 21:46:26
【问题描述】:

我需要在照片周围和我想要附加文字的照片下方添加边框。但是,到目前为止,我可以添加边框或添加文本,但它们不能一起工作。

我的意思是,附加文本:

convert photo.jpg -background White label:"A nice memory" -background White -gravity east -append result.jpg

这会在图像的右下角添加一个带有文本的白色条带:

以及添加边框:

convert photo.jpg -bordercolor Green -border 5%x10% result.jpg

它在照片周围添加了漂亮的绿色边框。但是,如果我想让它们在一起:

convert photo.jpg -bordercolor Green -border 5%x10% -background White label:"A nice memory" -background White -gravity east -append result.jpg

它首先添加一个边框,然后在下边框下方添加一条带有文本的额外空间。我想我必须明确告诉它边框和文本在一起。这可能吗?

预期:

(重要提示:我希望文字与照片右对齐,就像没有边框一样)

谢谢!

【问题讨论】:

  • 一张你所拥有的照片和另一张你想要的照片比描述什么不起作用的几段要好得多......
  • 没错!让我来做。
  • @MarkSetchell 添加。

标签: imagemagick imagemagick-convert


【解决方案1】:
convert input.jpg -bordercolor Green -border 5%x10% -gravity southeast -annotate +0+0 "Some text" result.jpg

【讨论】:

  • 谢谢!这最有效,我需要弄清楚如何将文本与照片本身右对齐,而不是与边框。
  • 如果你有一个固定的边框而不是一个 % 你可以在 -annotate 中将 +0+0 调整为 -20+0 之类的东西
【解决方案2】:

在 Imagemagick 6 中,您可以按如下方式进行操作(unix 语法):

infile="logo:"
offx=`convert $infile -format "%[fx:5*w/100]" info:`
offy=`convert $infile -format "%[fx:2.5*w/100]" info:`
convert $infile -bordercolor Green -border 5%x10% -font Arial -pointsize 18 -gravity southeast -annotate +${offx}+${offy} "Some text" result.jpg


在 Imagemagick 7 中,您可以这样做:

magick logo: -bordercolor Green -border 5%x10% -font Arial -pointsize 18 -gravity southeast -annotate +%[fx:5*w/100]+%[fx:(10/4)*h/100] "Some text" result.jpg


可能需要针对 pint-size 调整偏移量(1/4 值),以便文本在提供的空间中垂直居中。

图像 logo: 是一个内部 Imagemagick 图像,需要冒号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多