0

例如,我有 4 张尺寸为1000x800的图像。我想将所有这些图像合并为一张图像。我知道有一个命令

convert +append image[1-4].jpg output.jpg

但我想通过重叠250 像素将第二张图像合并到第一张图像中。

即,在我的最终图像中,image1 以及 image2 和 3 具有 750 个像素,最后一个图像具有 1000 个像素。

通过使用上面的转换命令,我们将得到一个4000x800的图像大小,但这里我希望它是 ((750*3)+1000*1)x800。即3250x800

另外,我怎样才能通过垂直附加来做到这一点?

4

3 回答 3

2

“+smush”操作符的作用类似于“+append”,但它需要一个参数。正数将附加由那么多像素分隔的图像。负数将附加具有那么多重叠的图像。您的示例命令将如下所示...

convert image[1-4].jpg +smush -250 output.jpg

要垂直附加图像,请使用运算符的“-smush”形式。在任何一种情况下,操作员都将根据当前的“-gravity”设置对齐图像。

于 2018-01-05T16:30:47.903 回答
1

你没有说你想如何重叠它们。如果不需要混合,那么在 ImageMagick 中,可以使用 smush 而不是 append。Smush 允许偏移(间隙)或重叠。前者具有正值,后者具有负值以重叠后续图像。-smush 垂直附加,+smush 水平附加。当对参数使用正值时,背景颜色控制间隙的间距。

所以试试

convert image[1-4].jpg +smush -256x0 output.jpg

或者

convert image1.jpg image2.jpg image3.jpg image4.jpg +smush -256x0 output.jpg

或者如果这些是唯一具有该语法的图像,那么

convert image*.jpg +smush -256x0  output.jpg
于 2018-01-05T05:32:50.727 回答
0

我刚刚在 Imagemagick 6.9.9.33 Q16 Mac OSX 中测试了以下内容。

请注意,我使用带有正值的 -smush 进行了测试,以便查看间隙而不是重叠。那只是为了测试。如果您遵循最后一个命令,如果您想重叠而不是在图像之间放置间隙,它应该可以很好地处理负值。

创建 13 个名为rose0.jpg ... rose12.jpg 的图像

convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "0" test/rose0.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "1" test/rose1.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "2" test/rose2.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "3" test/rose3.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "4" test/rose4.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "5" test/rose5.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "6" test/rose6.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "7" test/rose7.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "8" test/rose8.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "9" test/rose9.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "10" test/rose10.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "11" test/rose11.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "12" test/rose12.jpg


然后把它们弄糊涂。这失败了,只附加了 0-2。(我认为这种结构仅限于它看到的任何数字)

convert test/rose[0-12].jpg -smush 10 test/rose_smush.jpg

在此处输入图像描述

如果仅使用一位数字,则此方法有效。

convert test/rose[0-9].jpg -smush 10 test/rose_smush.jpg

在此处输入图像描述

正确的方法是使用以下结构。

convert test/rose%d.jpg[0-12] -smush 10 test/rose_smush.jpg

在此处输入图像描述

请参阅http://www.imagemagick.org/script/command-line-processing.php上的文件名参考部分

于 2018-01-08T18:13:55.453 回答