Imagemagick: stack images horizontally/vertically and match height/width

0

For example 1.jpg, 2.jpg which are of dimension axb, cxd.

If I run something like convert +append 1.jpg 2.jpg out.jpg. I'd like the out.jpg be (a+c)xb or (a+c)xd.

If I run something like convert -append 1.jpg 2.jpg out.jpg. I'd like the out.jpg be ax(b+d) or cx(b+d).

Is it possible to do with Imagemagick?

johan

Posted 2018-12-03T13:55:01.770

Reputation: 126

Answers

0

I ended up writing a little script.

Append two images horizontally and match to the minimum height:

h1=$(identify -ping -format "%h" 1.jpg) &&
h2=$(identify -ping -format "%h" 2.jpg) &&
min_h=$(( h1 < h2 ? h1 : h2 )) &&
convert 1.jpg -resize x$min_h\> 1_shrink.jpg &&
convert 2.jpg -resize x$min_h\> 2_shrink.jpg &&
convert +append 1_shrink.jpg 2_shrink.jpg out.jpg &&
rm 1_shrink.jpg 2_shrink.jpg

Append two images vertically and match to the minimum width:

w1=$(identify -ping -format "%w" 1.jpg) &&
w2=$(identify -ping -format "%w" 2.jpg) &&
min_w=$(( w1 < w2 ? w1 : w2 )) &&
convert 1.jpg -resize $min_w\> 1_shrink.jpg &&
convert 2.jpg -resize $min_w\> 2_shrink.jpg &&
convert -append 1_shrink.jpg 2_shrink.jpg out.jpg &&
rm 1_shrink.jpg 2_shrink.jpg

If you want to match to the maximum dimension of the two images, just change the condition in parentheses from < to >.

johan

Posted 2018-12-03T13:55:01.770

Reputation: 126