How to create a canvas and fill it with a lot of pictures?

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
sostaco
Posts: 2
Joined: 2019-01-27T11:05:00-07:00
Authentication code: 1152

How to create a canvas and fill it with a lot of pictures?

Post by sostaco »

Hello everybody, i have som problems trying to create an image with imagemagick, and probably you could help me try to figure out how to do it.

I need to create a image with a specific size ( in this case, 148mm x 210mm size ), and then fill it with a lot of pictures that i have inside a folder.

The amount of images is between 40 and 60 images per page, and if for some reason, it reaches the end of the pictures and the canvas is not full, start again from the first one until complete the background image.

This is how i made until now.
magick montage *.jpg -geometry +0+0 -mode Concatenate result.jpg

pause
I need to know how to create the canvas with the specified width and high and to resize the montage pictures to fit in the background image.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create a canvas and fill it with a lot of pictures?

Post by fmw42 »

Imagemagick does not work in units of mm. It works in pixels. Your aspect ratio is w/h = 148/210 = 0.705. So you need to make a background image with that proportion, composite your images over the background at appropriate places (or us append to put them side by side), then set the output density to scale so that when printed it would have your desired 148x210 mm.

Unfortunately, montage does not work with some desired output size. It will composite all your and create an output size whatever is needed for the -tile arrangement you specify.

The best approach is to create a list of all the images dimensions from your folder. Then compute how many you need to put in each row for a give width and append them. Then do the next row. Then when you have enough rows to achieve the desired height so that the aspect ratio is achieved, you stop and append all the rows. This will require scripting.

How big are your input images and how many do you want in a row? Are your input images all the same size.

I think you need to explain better or show an example output image.


________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create a canvas and fill it with a lot of pictures?

Post by fmw42 »

Another possible approach might be to compute how big you want the montage in pixels so that the aspect ratio is 0.705 on the basis of how big your images are and how many you want in each row and column. That determines how many tiles you get horizontally and vertically (and the total number of tiles). Then use -geometry in montage to resize the images to the width/xtiles and height/ytiles. Then read that many image into montage. Montage will scale each image to fill the size of the tiles such that you get the desired output size. Then compute the needed density to produce 148x210 mm printed image and assign that density in montage using -density.
sostaco
Posts: 2
Joined: 2019-01-27T11:05:00-07:00
Authentication code: 1152

Re: How to create a canvas and fill it with a lot of pictures?

Post by sostaco »

According to the image, the size in pixels is 420x595, can i set this size on the bat file to make the program fit the images in?

Thanks for the reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create a canvas and fill it with a lot of pictures?

Post by fmw42 »

sostaco wrote: 2019-01-27T15:49:42-07:00 According to the image, the size in pixels is 420x595, can i set this size on the bat file to make the program fit the images in?

Thanks for the reply
Not necessarily. How big are each of your input images? If your input images are larger than that, then you cannot montage them into that size unless you shrink all your input image.

I think you would be better to scale 420x595 to the number of rows and columns that you want and then adjust the density so that it prints to your desired size in mm.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create a canvas and fill it with a lot of pictures?

Post by fmw42 »

Here is an example in Unix syntax:

Your base size at 72 dpi would be:

148mm*72dpi/25.4 mm per inch = 420
210mm*72dpi/25.4 mm per inch = 595

Lets double that because I have images that are about 256x256 size so that we can get about 4 columns and 5 rows

So the output should be 2 * 420 = 840 and 2 * 595 = 1190.

Now we want 4 column so each tile width would be 840/4 = 210. But allowing 2 pixels between lets trim down to 200 width. Likewise we want 5 rows so the tile height would be 1190/5 = 238. So lets use 220.

Now I have only 5 images that I will repeat 4 times to get 20 input images.

So I would do

Code: Select all

montage \
lena.jpg barn.jpg monet2.jpg mandril3.jpg zelda1.jpg \
\( -clone 0-4 \) \
\( -clone 0-4 \) \
\( -clone 0-4 \) \
-tile 4x5 -geometry 200x220+2+2 \
miff:- |\
convert - -gravity center -background white -extent 840x1190 -units pixelspercentimeter -density 56.7 montage_20_result.jpg
Where I have piped the result of the montage which is smaller than 840x1190 to a convert to extend it centered in a white background to 840x1190.

I have set the density and units to achieve your desired 148x210 mm ( or 14.8x21 cm)

840 pixels / 14.8 cm = 56.7
1190 pixels / 21.0 cm = 56.7


Image
Post Reply