1

I want to be able to tile together images of different aspect ratios in a way that looks good and avoids as much whitespace between the images as possible.

What I've done so far is rename all the images using a script that changes the image name to the aspect ratio, which makes ImageMagick tile the narrowest images first:

enter image description here

for i in *.jpg;
    do mv "$i" $(printf '%.4f' $(echo "scale=4;" $(identify -format "%w" "$i") "/" $(identify -format "%h" "$i") | bc))"$i";
done

Then I run ImageMagick:

montage -mode concatenate -tile 6x -geometry 250x+10+20 -background black *.jpg out.jpg

Which gives me something like this:

enter image description here

Unfortunately, I want something like this, where there isn't as much vertical space between the images with the smaller aspect ratios and bigger ones:

enter image description here

Anyone have any ideas?

0xbad1d3a5
  • 126
  • 1
  • 6
  • Cool question! I did something somewhat related a while ago so maybe have a look at that while I, and others, are thinking... https://stackoverflow.com/a/30625536/2836621 – Mark Setchell Jul 12 '18 at 08:46
  • I think that by fixing the width to 250px, you have forced ImageMagick to vary the height because it doesn't like changing aspect ratios unless you use a forcing `!`. What happens if you remove the `250x`? Or if you use `-gravity center -extent 250x` to make all your images 250px wide first? – Mark Setchell Jul 12 '18 at 09:03
  • Oh hey, your bash script worked pretty well. I just didn't want to write something like that. I was hoping for something lighter though haha. I'm not sure what -extent does. I tried it and it's giving weird results. Do I replace geometry with extent in my montage query? Also. it looks like your script is turning everything black and white. I'm not seeing any colorspaces being set in the script so that's kinda confusing. Any clue why that be happening? – 0xbad1d3a5 Jul 12 '18 at 09:59
  • No, I meant to run through a loop first making all the images 250px wide, then, **afterwards**, do your `montage` without the `250x`. So, `for i in *.jpg; do convert "$i" -background white -gravity center -extent 250x "$i" ; done` then your `montage` with the `250x` omitted. – Mark Setchell Jul 12 '18 at 10:56
  • `-extent` just pads out an image with the background colour till it fills the specified size. – Mark Setchell Jul 12 '18 at 10:57
  • Oh hey! That worked, thanks! Do you want to answer the question then? Your script also works pretty well, though I keep getting black and white images. Would you know why that's the case? – 0xbad1d3a5 Jul 13 '18 at 03:22

0 Answers0