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?

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 >.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.