imagemagickmontage

specify a border and exact space between images


I want to have a picture like this:

TTTTTTTTTTTTTTTT
E P1 F P2 F P3 E
================
E P4 F p5 F P6 E
BBBBBBBBBBBBBBBB

where P{1..6} are rectangular pictures which are equally sized, E denotes some horizontal spacing, = denotes some vertical spacing, T denotes some top spacing, and B denotes some bottom spacing.

I would like to do this with just one command, but I am fairly sure that it's actually not possible to express this with montage.

It is probably possible to do it with multiple montage calls, however. I didn't try that yet, but more in general it seems montage is a rather special purpose tool with a rather weak grammar to express pictures.

Is there something better for this particular task (scriptable)?


Solution

  • If T, B, E, =, F are different values, and P{1..6} are different images. It might not be worth attempting short-cuts, but build out each row, and column specifically. The following example is one ImageMagick command using bash variables as placeholders.

    B="-size x15 xc:"
    E="-size 5x  xc:"
    F="-size 10x xc:"
    T="-size x25 xc:"
    V="-size x20 xc:" # V is an alias for `=`
    
    EQUALLY_SIZED="-size 20x30"
    P1="${EQUALLY_SIZED} xc:CadetBlue1"
    P2="${EQUALLY_SIZED} xc:firebrick"
    P3="${EQUALLY_SIZED} xc:ForestGreen"
    P4="${EQUALLY_SIZED} xc:lavender"
    P5="${EQUALLY_SIZED} xc:LemonChiffon"
    P6="${EQUALLY_SIZED} xc:OldLace"
    
    convert $T \
            \( $E $P1 $F $P2 $F $P3 $E +append \) \
            $V \
            \( $E $P4 $F $P5 $F $P6 $E +append \) \
            $B \
            -append \
            output.png
    

    specify a border and exact space between images

    This example works because B, T, & V have no value except height. And E & F have no value but width. If we update the FPO spacer images as orange canvas...

    O="xc:orange"
    B="-size x15 ${O}"
    E="-size 5x  ${O}"
    F="-size 10x ${O}"
    T="-size x25 ${O}"
    V="-size x20 ${O}" # V alias `=`
    

    ... we can verify the expected results.

    verify or proof