代码之家  ›  专栏  ›  技术社区  ›  kcsurapaneni

使用Imagemagick在某些像素级别重叠多个图像

  •  0
  • kcsurapaneni  · 技术社区  · 7 年前

    例如,我有4张大小为的图像 1000x800 . 我想把所有这些图像合并成一个图像。我知道有一个命令

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

    但是我想通过以下方式将第二个图像合并到第一个图像中: 重叠 250像素。

    i、 例如,在我的最终图像中,image1和image2有750个像素;3,最后一个图像有1000个像素。

    通过使用上述 转换 4000x800 ,但这里我希望它是((750*3)+1000*1)x800。即。, 3250x800 .

    另外,如何通过垂直附加来实现这一点?

    3 回复  |  直到 6 年前
        1
  •  2
  •   GeeMack    7 年前

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

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

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

        2
  •  1
  •   fmw42    7 年前

    你没有说你想如何重叠它们。如果不需要混合,那么在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
    
        3
  •  0
  •   fmw42    7 年前

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

    注:我使用带正值的-smush进行测试,以查看间隙而不是重叠。那只是为了测试。如果您按照最后一个命令操作,如果您希望重叠图像而不是在图像之间设置间隙,则可以使用负值。

    创建13个名为rose0的图像。jpg。。。玫瑰12.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
    

    enter image description here

    如果只使用一位数字,则此操作有效。

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

    enter image description here

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

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

    enter image description here

    http://www.imagemagick.org/script/command-line-processing.php

    推荐文章