如何在图像中添加输入编号?

时间:2015-01-28 10:21:29

标签: image-processing imagemagick

我想要一个输入数字和图像的脚本,然后将数字写在图像的一角。

然后我会将此脚本概括为两个输入的列表。

但是,我不知道是否有特定的语言/应用程序来进行这种图像处理。

1 个答案:

答案 0 :(得分:7)

我推荐ImageMagick,它是免费的,安装在大多数Linux发行版上,并且很容易安装在Windows和Mac OSX上。可从 - here下载。您可以在命令行或PHP / Perl / Ruby和大多数其他语言中使用它。

在命令行中,您可以执行以下操作:

convert input.jpg -gravity southeast \
          -stroke '#000C' -strokewidth 2 -annotate 0 'Dail Beagh' \
          -stroke  none   -fill white    -annotate 0 'Dail Beagh' \
          output.jpg

enter image description here

或者这......

convert input.jpg -fill red -undercolor '#00000080' -gravity SouthWest \
        -annotate +0+5 'Dail Beagh' output2.jpg   

enter image description here

或任意数量的其他版本 - link

如果要编写脚本,可以将以下内容保存在名为title

的文件中
#!/bin/bash
image=$1
title=$2

convert "$image" -gravity southeast \
          -stroke '#000C' -strokewidth 2 -annotate 0 "$title" \
          -stroke  none   -fill white    -annotate 0 "$title" \
          output.jpg

convert "$image" -fill red -undercolor '#00000080' -gravity SouthWest \
        -annotate +0+5 "$title" output2.jpg   

然后使用

使其可执行
chmod +x title

然后用

运行它
./title "input.jpg" "some funky title"

或者如果您特别想要一个数字

./title "some image somewhere.png" 56

enter image description here

或者,假设您将一些现成的数字保存为GIF个文件,例如

<强> 0.gif

enter image description here

9.gif

enter image description here

您可以将它们并排添加以制作如下标签:

convert 9.gif 9.gif 0.gif +append label.gif

要做到这一点:

enter image description here

然后使用

将其叠加到您的图像上
convert input.jpg -gravity southeast label.gif -composite output.jpg

enter image description here

或者,你可以一起做到这一点:

convert input.jpg -gravity southeast   \
    \( 9.gif 9.gif 0.gif +append \)    \
    -composite output.jpg
相关问题