使用ImageMagick(或类似)覆盖图像的文件名 [英] Overlaying an image's filename using ImageMagick (or similar)

查看:141
本文介绍了使用ImageMagick(或类似)覆盖图像的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道ImageMagick的 annotate 命令可以在图像上叠加一些文字,但是它可以使用图像的文件名作为此文本吗?我会这么认为,但似乎无法找到确认这一点的直接文档。

I know ImageMagick's annotate command can superimpose some text over an image, but can it use the image's filename as this text? I would've assumed so, but can't seem to find direct documentation that confirms this.

毫无疑问,某些参数组合可以管理这个,或者是否有更好的在脚本中这样做的方法?

No doubt some combination of parameters can manage this, or is there a better way of doing this in a script?

推荐答案

Eric L.的回答是正确的 - 来自我的+1! - 但 -annotate 并不能让你对文本的外观有太多控制。

Eric L.'s answer is correct -- +1 from me for it! -- but -annotate doesn't give you much control over the appearance of the text.

如果你看为了漂亮,然后去寻找使用 -composite 的东西。您可以使用IM命令首先构建叠加图像(使用半透明背景),然后将其覆盖在原始图像上。

If you look for prettyness, then rather go for something that uses -composite. You can use an IM command to construct an overlay image first (which uses a semi-transparent background) and then overlay it over the original image.

这是一个示例如何用 -composite 代替 -annotate ,使用脚本方法处理当前目录中的每个PNG文件。这个甚至自动调整字体大小并使其适合可用的宽度* 90% - 它是一个Bash脚本(请参阅Win等效的评论):

Here is an example how to do it with -composite instead of -annotate, using a scripted approach that processes every PNG file in the current directory. This one even automatically adapts the font size and fits it into the available "width * 90%" -- it is a Bash script (see comments for Win equivalent):

for img in *.png; do

   width=$(identify -format %W ${img})
   width=$(( ${width} * 9 / 10 ))

   convert                  \
     -background '#0008'    \
     -gravity center        \
     -fill white            \
     -size ${width}x100     \
      caption:"${img}"      \
      "${img}"              \
     +swap                  \
     -gravity south         \
     -composite             \
      "with-caption-${img}"

done

下面是一个原件和相应输出的示例说明:

An example illustration for one original and the respective output are below:

  !

这是一个使用 -annotate 的命令,试图设置一些超出默认参数的东西:

Here is a command that uses -annotate, trying to set a few things beyond the default parameters:

for img in so#12231624-right.png; do

   convert                   \
      "${img}"               \
     -fill red               \
     -undercolor '#0008'     \
     -pointsize 24           \
     -gravity south          \
     -annotate +0+5 "${img}" \
      "with-annotate-${img}"

done

 

这篇关于使用ImageMagick(或类似)覆盖图像的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆