DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+2 votes

I have a folder with 100s of images. I would like to create a single image containing all my pictures, tiled together in a custom grid for example 10x10 or 20x10. The images are not all of the same size, but I would like all the tiles to be equal in size. Doing this manually is a lot of work, so I would like to know if there is a way of automating the process.

by

1 Answer

+4 votes
 
Best answer

Graphicsmagick's montage command should be useful for this. You could do something like:


gm montage -frame 3 -tile 5x5 -geometry 200x200+2+2 /path/to/image/dir/*.jpg single.jpg

  • -frame 3 adds a 3px frame around the tiles (minimum 2 px)
  • -tile 5x5 specifies the number of images per row and column (adjust this according to the number of images)
  • -geometry 200x200+2+2 generates tiles 200px, adds a 2px border around images, the images are resized to fit within the tiles and fills the remaining space inside the tiles with a background colour

Result:

Image source: Pexels

If the images themselves need to be same size, i.e. fill each tile completely, I'm not yet aware of a way to do it with montage in one command. A clunkier approach might be to pre-generate thumbnails with gm convert and then use the command above to montage them. This example would make 200px square tiles:

#!/bin/bash

basedir=/path/to/parent/dir
cp -r $basedir/images $basedir/thumbs
for img in $(find $basedir/thumbs -regex ".*\.\(jpg\)"); do
  gm convert -verbose "$img" -resize 200x200^ -extent 200x200^ -gravity center "$img"
done
gm montage -verbose -tile 5x5 -geometry +2+2 $basedir/thumbs/*.jpg $basedir/single.jpg
rm -r $basedir/thumbs

Result:

Image source: Pexels

If the tiles do not have to be the same size, gmic (CLI or integration within GIMP as filters) and PhotoCollage (GUI) can also do montages.

by
selected by
0

Thank you for the very detailed answer! montage worked perfectly for me!

Contributions licensed under CC0
...