montage minimize row/column size?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jamadagni
Posts: 11
Joined: 2013-12-06T19:03:10-07:00
Authentication code: 6789

montage minimize row/column size?

Post by jamadagni » 2017-11-03T02:16:28-07:00

I have nine squares of varying sizes generated by:

Code: Select all

colors=("" 4d2600 590000 730055 2c0059 000080 004d00 638000 ffaa00 323232)
for x in {1..9} ; do
    convert -size $((40 + x * 10))x$((40 + x * 10)) xc:"#${colors[$x]}" $x.png
done
Now I'm trying to montage it so that there is no bordering space between the squares.

As per the method advised under the usage pages (huge thanks to Anthony!) I tried:

Code: Select all

montage ?.png -geometry '1x1+0+0<' out.png
but it is still producing some space between the squares:

Image

I realize it's only because of the difference in size between the tiles. So is there any way to tell montage to not make all tiles the equal size but only size them enough to fit the biggest item in the particular row/column? Or if that is outside the scope of montage then how else using IM can I do that?

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: montage minimize row/column size?

Post by fmw42 » 2017-11-03T09:30:05-07:00

I do not think that will work for unequal sizes, since montage will pad to maximum size.

jamadagni
Posts: 11
Joined: 2013-12-06T19:03:10-07:00
Authentication code: 6789

Re: montage minimize row/column size?

Post by jamadagni » 2017-11-03T09:32:26-07:00

Thanks for your reply. Is there some way to use convert for this then?

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: montage minimize row/column size?

Post by fmw42 » 2017-11-03T09:39:01-07:00

No, I tried append, but you still have space between most of the images. Try this and you will see

Code: Select all

convert -gravity center \
\( 1.png 4.png 7.png -append \) \
\( 2.png 5.png 8.png -append \) \
\( 3.png 6.png 9.png -append \) \
+append result.png
or

Code: Select all

convert -gravity center \
\( 1.png 2.png 3.png +append \) \
\( 4.png 5.png 6.png +append \) \
\( 7.png 8.png 9.png +append \) \
-append result2.png
Perhaps if you showed or explained what you expect, we could try to achieve that.

jamadagni
Posts: 11
Joined: 2013-12-06T19:03:10-07:00
Authentication code: 6789

Re: montage minimize row/column size?

Post by jamadagni » 2017-11-03T21:17:22-07:00

I want the size of each tile to be that of the biggest image in its row/column, not the entire grid. See:

Image

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: montage minimize row/column size?

Post by fmw42 » 2017-11-03T22:30:03-07:00

Try this. You must get the largest size tile and add 1 to its width and height and use that as below where the black tile is largest and is 130x130.

Code: Select all

convert -background white -gravity center \
\( 1.png 2.png 3.png -extent 131x131 +append -trim +repage \) \
\( 4.png 5.png 6.png -extent 131x131 +append -trim +repage \) \
\( 7.png 8.png 9.png -extent 131x131 +append -trim +repage \) \
-append result3.png

jamadagni
Posts: 11
Joined: 2013-12-06T19:03:10-07:00
Authentication code: 6789

Re: montage minimize row/column size?

Post by jamadagni » 2017-11-03T22:37:27-07:00

Thanks for your efforts but sorry, the result is still not what is desired. If you compare to the image I posted above, you can see that in the result of your command the three columns aren't touching each other (in the bottom right which contains the widest elements). Anyhow, if there is no way to automatically do this without manually finding the size of the biggest item, we can just give up.

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: montage minimize row/column size?

Post by fmw42 » 2017-11-03T22:42:01-07:00

try this

Code: Select all

convert -background white -gravity center \
\( 1.png 2.png 3.png -extent 131x131 +append -trim +repage \) \
\( 4.png 5.png 6.png -extent 131x131 +append -trim +repage \) \
\( 7.png 8.png 9.png +append \) \
-append result4.png

Post Reply