How to merge images in a single PDF or image file

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

I was doing something similar the other day. Grids are in, it seems. In my case I had a variable number of images being piped into the grid and I just wanted to create a 17 wide image by however many images tall.

montage -mode concatenate $(printf 'rose: %.0s' {1..136}) -resize 100x80 -tile 17x output.jpg

That just uses 136 rose images to form a 8-tile-high grid. Obviously you'll want to change the $(...) group for a list of your input images. And you'll want to set the tile variable to something like 2x if you just want to set the number of tiles.

In terms of outputting to PDF, you can just change the extension. So you would be looking at something like:

montage -mode concatenate $(printf 'rose: %.0s' {1..5}) -tile 2x out.pdf