0

For example, I have 4 images with a size of 1000x800. I want to merge all these images into one image. I know there is a command of

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

But I want to merge the second image into the first image by overlapping 250 pixels.

i.e., In my final image, image1 has 750 pixels as well as image2 & 3 and the last image has 1000 pixels.

By using above convert command, we will get an image size of 4000x800, but here I want it to be ((750*3)+1000*1)x800. i.e., 3250x800.

Also, how can I do this by appending vertically?

fmw42
  • 46,825
  • 10
  • 62
  • 80
KCS
  • 442
  • 5
  • 20

3 Answers3

2

The "+smush" operator will act like "+append", but it takes an argument. A positive number will append the images separated by that many pixels. A negative number will append the images with that much overlap. Your example command would look like this...

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

To append images vertically, use the "-smush" form of the operator. In either case the operator will align the images according to the current "-gravity" setting.

GeeMack
  • 4,486
  • 1
  • 7
  • 10
1

You do not say how you want to overlap them. If you do not need to blend, then in ImageMagick, you can use smush rather than append. Smush allows offsets (gaps) or overlaps. The former with positive values and the latter with negative values to overlap succeeding images. -smush appends vertically and +smush appends horizontally. The background color controls the spacing for gaps when using positive values for the argument.

So try

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

or

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

or if those are the only images with that syntax, then

convert image*.jpg +smush -256x0  output.jpg
fmw42
  • 46,825
  • 10
  • 62
  • 80
  • what about if I have 15 images I want to merge. I used _convert image[0-14].jpg +smush -256x0 output.jpg_ but it is not working as expected. I know I can use _image*.jpg_, but there are other images with same naming convention – KCS Jan 08 '18 at 06:43
  • What is the exact naming convention of your images? Do you have leading zeros such as image001.jpg rather than image1.jpg? Do you have too many images to hold in RAM plus the equivalent for the output image to be in RAM as well? What kind of error are you getting? – fmw42 Jan 08 '18 at 07:29
  • the thing is if I want to add image0 to image14, I have to add it as sequentially. i.e. image0,image1, image2, image3,....imgae13,image14. But, when we use image*.jpg it will choose it's own order like image0, image10,image11, ....image14,image1,image2,image9 like this – KCS Jan 08 '18 at 07:38
  • To use image*.jpg, you would need to use leading zeros, since that structure lists images alphabetically, not numerically. – fmw42 Jan 08 '18 at 18:38
0

I just tested the following in Imagemagick 6.9.9.33 Q16 Mac OSX.

Note I tested using -smush with positive values so as to see gaps and not overlaps. That was just for testing. If you follow the last command, it should work fine with negative values, if you want to overlap rather than put gaps between the images.

Create 13 images named 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


Then smush them. This fails and only appends 0-2. (I think this stucture is limited to whatever digits it sees)

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

enter image description here

This works if using only one-digit numbers.

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

enter image description here

The proper way to do this is to use the following structure.

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

enter image description here

See the section of Filename Reference at http://www.imagemagick.org/script/command-line-processing.php

fmw42
  • 46,825
  • 10
  • 62
  • 80