Ubuntu – How to merge images in a single PDF or image file

command lineimage processing

I have some images which I want to merge. By this I mean that if I have 5 images, I want to arrange them in this way:

tiling layout

I want to do this using a command so that I can use a Bash script for it. For example the command could be like this:

foo image1 image2 image3 image4 image5

I have lots of images so the command should be able to process a large number of files.

The output can be PDF or even in image format.

Best Answer

See the montage command from imagemagick (sudo apt-get install imagemagick).

montage -geometry 250x250+0+0 image1.png image2.png out.png

This will resize each image (to 250px with no deformation) and combine them with no margin.

More montage examples.


You can also use convert (example with wildcards):

convert -append pixpixp-*.jpg newpix.jpg