Arranging images into grid

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
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Arranging images into grid

Post by VanGog »

Does IM enables to arrange images and join them like in grid system? For example, maps are divided into squares, which when joined together give one large image. This assumes that all images are same size of sure. Does IM has some algorithm that could be used to organize images into grid? I mean something like to specify size of square (or rectangle shape) and number of columns and rows. Then just to specify in which column/row the image should be added.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Arranging images into grid

Post by fmw42 »

You would have to compute the coordinates for the upper left corner of the image which corresponds to the grid intersection where you want to place the image. Then you would just use -geometry +X+Y -compose over -composite to place it on the background image. Alternately, if you want to do several at one time, then you can use -page +X+Y ... -flatten.

see
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/layers/#flatten


If you want to merge a bunch of images into a grid system, you can use montage.

see
http://www.imagemagick.org/Usage/montage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Arranging images into grid

Post by anthony »

At this time the only true 'grid' processing of images is provided by "montage"

however new 'layout' methods are planed for an early IMv7 version (once released) that will allow you to select different options. See a summery of some ideas in
http://www.imagemagick.org/Usage/bugs/future/#layout


Ideas are welcome!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: Arranging images into grid

Post by VanGog »

If I would need to calculate coordinates manually, that would be big problem for me. There would be too much of programming. I use CMD, and I have to say, I am just beginner in batch file programming.

I will tell you what is my situation. I have many bmp files that are big size 4096x4096 and I am going to resize them to little images... In next step I would need to specify which files should be "montaged" into file with a specific name. The number of files is cca 2200.

For example source files would have these names:

Code: Select all

17480_11032	17488_11032	17496_11032	17504_11032	17512_11032	17520_11032	17528_11032	17536_11032	17544_11032	17552_11032
17480_11040	17488_11040	17496_11040	17504_11040	17512_11040	17520_11040	17528_11040	17536_11040	17544_11040	17552_11040
17480_11048	17488_11048	17496_11048	17504_11048	17512_11048	17520_11048	17528_11048	17536_11048	17544_11048	17552_11048
17480_11056	17488_11056	17496_11056	17504_11056	17512_11056	17520_11056	17528_11056	17536_11056	17544_11056	17552_11056
17480_11064	17488_11064	17496_11064	17504_11064	17512_11064	17520_11064	17528_11064	17536_11064	17544_11064	17552_11064
17480_11072	17488_11072	17496_11072	17504_11072	17512_11072	17520_11072	17528_11072	17536_11072	17544_11072	17552_11072
17480_11080	17488_11080	17496_11080	17504_11080	17512_11080	17520_11080	17528_11080	17536_11080	17544_11080	17552_11080
17480_11088	17488_11088	17496_11088	17504_11088	17512_11088	17520_11088	17528_11088	17536_11088	17544_11088	17552_11088
17480_11096	17488_11096	17496_11096	17504_11096	17512_11096	17520_11096	17528_11096	17536_11096	17544_11096	17552_11096
17480_11104	17488_11104	17496_11104	17504_11104	17512_11104	17520_11104	17528_11104	17536_11104	17544_11104	17552_11104
17480_11112	17488_11112	17496_11112	17504_11112	17512_11112	17520_11112	17528_11112	17536_11112	17544_11112	17552_11112
17480_11120	17488_11120	17496_11120	17504_11120	17512_11120	17520_11120	17528_11120	17536_11120	17544_11120	17552_11120
17480_11128	17488_11128	17496_11128	17504_11128	17512_11128	17520_11128	17528_11128	17536_11128	17544_11128	17552_11128
It is just little segment from a table. I must to create batch file to tell to your program that I want file 17480_11032.bmp to be set in the grid as 1,1 (col,row); file 17488_11032 would be in (1,2) position, 17496_11032 on (1,3), 17504_11032 on (1,4) and so on. So I would need to think up mechanism for batch file to process to correct name to correct column,row coordinates. That would be one thing.

Basic variables in the CMD script should be first position of the first image, and x a y size of the square or rectangle. Or to find way how to define some system to place the image on correct place. As I say, I am beginner and I worry of long labyrinthine codes.

But I think that calculation of pixel position for every position should do ImageMagick. It would simplify much of work of the CMD programmer.

I tried the last link from anthony but it does not work. When should we welcome the new product IM7? What does mean "(once released)" is it downloadable?
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: Arranging images into grid

Post by VanGog »

I read about the montage and it seems to me, that this is good enough to reach my task. As I understand it, only thing I must to include is -geometry to specify square size, -tile to specify rows and columns and source files and destination. Only think I must do is to feed the command parameter with the files, which I could do in for loops. I'm very happy that I found here solution. Thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Arranging images into grid

Post by anthony »

Montage is exampled in detail in
http://www.imagemagick.org/Usage/montage/

But you are right you really only need to set -geometry (tile size and spacing) and the -tile But tile only needs to know the number of columns or rows you want. It will calculate the other value basied on the number of images.

A seperate tiling step is probably best considering the size of the images being thumbnailed.

Have a look at "mogrify" (caution by default it is a 'in-place' image modifier - make backups!)

See http://www.imagemagick.org/Usage/basics/#mogrify
The second example (with a -path argument) should be something like what you are after
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: Arranging images into grid

Post by VanGog »

Yes, I know. I read it. But your link
http://www.imagemagick.org/Usage/future/#layout
does not work.
Sorry that should be..
http://www.imagemagick.org/Usage/bugs/future/#layout

I fixed it above.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: Arranging images into grid

Post by VanGog »

I guess that the montage cannot to calculate with empty cells am I right?

I reallized I will need to solve this. Because I have empty cells in the grid so it is not like 30x30 images. So I probably will use empty image instead the empty cell.

So is it okay to use such syntax?

Code: Select all

montage empty.gif balloon.gif empty.gif medical.gif present.gif empty.gif shading.gif  montage.jpg empty.gif
I ask just to be sure that it will not exclude the images already stated.
Also my worry is that even if the empty.gif would be white image it will dis crease performnace. So tell me if have you any other solution how to skip image in the cell.

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

Re: Arranging images into grid

Post by fmw42 »

I believe that you can substitute null: for an image to make an empty space.

montage image1 image2 image3 null: image5 image6 null: null: image9 ....

see
http://www.imagemagick.org/Usage/montage/#null
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Arranging images into grid

Post by anthony »

VanGog wrote:If I would need to calculate coordinates manually, that would be big problem for me. There would be too much of programming. I use CMD, and I have to say, I am just beginner in batch file programming.
Actually programmed layout is rather easy to do. Just calculate the images position (virtual canvas offset), one image at a time, then -layer merge them together.

Examples of this type of processing is show in IM Examples, Laying Images, Programmed Layering
http://www.imagemagick.org/Usage/layers/#layer_examples
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: Arranging images into grid

Post by VanGog »

Great, thanks.
Post Reply