简体   繁体   中英

How can I make a montage with ImageMagick from images with different size and aspect ratio?

I have a lot of images, different sizes and aspect ratios. Is it possible to make a montage of them? I mean to optimally arrange them in rows after I set a common height for the images which build up a common row. Images aspect ratios aren't allowed to modify of course, and none of the images are allowed to omit from the final montage nor duplication.

The height of picture rows in the montage usually aren't equal, but their values should be kept in a minimal range (in statistical sense) or in other words: standard deviation from the mean value of the row heights must be minimized.

Desired width and height of the montage are given (a.)

Or the width and an allowed ratio range (or equivalently height range) is given (b.), for example width must be 1024 pixel, height must be so that w/h < 0.9 and w/h > 0.8

1.) Images must be packed in the montage in their initial fixed order. In this case one must find the images after what a new image row should be started in the montage (easy).

2.) Order of images is allowed to be altered. In this case one must find a permutation which lead to a minimalization of the standard deviation of the final row heights when each image is packed into the montage (hard).

For example:

在此输入图像描述

在此输入图像描述

I'm not sure I understand your question correctly.

Here is what I make of it. Assuming you have 8 different images of different sizes. For demo purposes, I'll let ImageMagick create these as 8 different color patches:

convert -size  90x90  xc:yellow  y.png
convert -size 120x120 xc:red     r.png
convert -size  60x210 xc:green   g.png
convert -size 150x180 xc:blue    b.png
convert -size  30x60  xc:cyan    c.png
convert -size 150x90  xc:magenta m.png
convert -size  90x120 xc:gray    Gr.png
convert -size 120x90  xc:black   K.png

You can montage these patches in many different ways:

convert \( y.png r.png g.png  b.png +append \)  \
        \( c.png m.png Gr.png K.png +append \)  \
       -append                                  \
       -mattecolor lightblue                    \
       -frame 1x1                               \
        montage0.png

This command does not scale the different patches. It places them in 2 rows a 4 patches and montages them in their original sizes. The white spaces is where the patches do not "fit":

montage0.png

convert \( y.png r.png g.png  b.png -resize x60 +append \)  \
        \( c.png m.png Gr.png K.png -resize x60 +append \)  \
       -append                                              \
       -mattecolor lightblue                                \
       -frame 1x1                                           \
        montage1.png

This command scales all different patches to a common height of 60 pixels (preserving their respective aspect ratios) and places them in 2 rows a 4 patches:

montage1.png

convert \( y.png r.png g.png  b.png -resize 60x +append \)  \
        \( c.png m.png Gr.png K.png -resize 60x +append \)  \
       -append                                              \
       -mattecolor lightblue                                \
       -frame 1x1                                           \
        montage2.png

This command scales all different patches to a common width of 60 pixels (preserving their respective aspect ratios) and places them in 2 rows a 4 patches:

montage2.png

convert \( y.png r.png g.png  b.png -resize 60x80\! +append \)  \
        \( c.png m.png Gr.png K.png -resize 60x80\! +append \)  \
       -append                                                  \
       -mattecolor lightblue                                    \
       -frame 1x1                                               \
        montage3.png

This command scales all different patches to dimensions of 60x80 pixels (overriding their original aspect ratios) and places them in 2 rows a 4 patches:

montage3.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM