[Solved] Repeat "multiple images" over fixed canvas size

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
Rye
Posts: 156
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

[Solved] Repeat "multiple images" over fixed canvas size

Post by Rye » 2018-11-07T11:55:22-07:00

So, since I once did a thread , that repeated a single image.

Now for "combining multiple images in the same folder and join them onto a canvas"

Code: Select all

montage *.png -size 400x400 -geometry 0 -tile %rep%x  tiled.png
... doesn't work (it obviously just repeats the same image till filled)

Code: Select all

for %x in (*png) do montage %x -size 400x400 -geometry 0 -tile %rep%x  tiled.png
... doesn't work either... (same approach basically).

Soo... how do I get this to:
a) take all images (tiles) in a folder into consideration for the "tiled.png" out file
b) do it from 001.png to... f.e. 056.png ?
so images like: 1 2 3 4 5 6 7 8

should be like
[1][2][3][4][5]
[6][7][8][9][1]
[2][3][4][5][6]

(until the canvas is filled to the given size)
- Thanks in advance

(sorry that this is a very similar question to an already exisiting one, hate being inefficient like this, but -montage and -tile were of no help... yet)
(PS: multiple -append and +appends are nice, but I would like to avoid it, as it would probably require recalculations for a specific x and y of the canvas each time)
Last edited by Rye on 2018-11-09T12:00:38-07:00, edited 1 time in total.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 10823
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Repeat "multiple images" over fixed canvas size

Post by snibgo » 2018-11-07T12:09:57-07:00

snibgo's IM pages: im.snibgo.com

Rye
Posts: 156
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Repeat "multiple images" over fixed canvas size

Post by Rye » 2018-11-07T12:48:27-07:00

As stated, I already had a look at it, but sadly I only managed to get either

- not the canvas size I wanted (script stopped when all tiles were used)

OR

- random canvas size.

I want to "fill up" a given size (say for example 560x890) with tiles (just for the sake of argument using 32x32 might suffice).
-tile {cols}x{rows} defines colums and rows but that'd require adjusting the tiles beforehand, and will most likely not repeat till filled.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

snibgo
Posts: 10823
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Repeat "multiple images" over fixed canvas size

Post by snibgo » 2018-11-07T13:19:23-07:00

I don't understand what you want. The example you give ...
Rye wrote:should be like
[1][2][3][4][5]
[6][7][8][9][1]
[2][3][4][5][6]
... uses some images twice. IM won't do that for you. If you want that, you'll need to script it.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 156
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Repeat "multiple images" over fixed canvas size

Post by Rye » 2018-11-07T13:43:27-07:00

I wrote the down twice, as they'd be used multiple times in order to fill the canvas.

For example:
*50 images 32x32px each
*filling a 1000x1000 canvas
=> repeating the images till the canvas is filled
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

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

Re: Repeat "multiple images" over fixed canvas size

Post by fmw42 » 2018-11-07T16:01:20-07:00

I think you need to find the largest width and height dimensions from all your input images, which will be the the montage cell size. Then compute how many cells will fit your desired canvas size in both width and height. Then compute how many repeats and partial repeats you need for the computed number of cells. Then input the list of repeated images to montage with the computed number of cells in width and height as the tile arguments.

User avatar
GeeMack
Posts: 645
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Repeat "multiple images" over fixed canvas size

Post by GeeMack » 2018-11-07T23:20:23-07:00

Rye wrote:
2018-11-07T13:43:27-07:00
For example:
*50 images 32x32px each
*filling a 1000x1000 canvas
=> repeating the images till the canvas is filled
This command reads in the tile images 000.png ... NNN.png, and appends them horizontally. Then it calculates the viewport needed to cover the area of the output canvas with those appended input tiles. Next it creates that viewport filled with repeating instances of the tiled images. Then it crops that horizontal strip into pieces the width of the output canvas and appends them vertically. It finishes with "-extent" to crop off any remainder from the bottom and write the output of the required canvas size.

Code: Select all

set WIDE=1000
set HIGH=1000
convert ???.png +append -size %WIDE%x%HIGH% xc: -virtual-pixel tile ^
   -set option:distort:viewport "%[fx:(v.w*v.h/u.h)+v.w]x%[fx:u.h]" ^
   ( -clone 0 -distort SRT 0 +repage -crop %WIDE%x0 -append +repage ) ^
   -delete 0,1 -extent %WIDE%x%HIGH% tiled.png
For IM version 7 use "magick" instead of "convert". To use in a BAT script you need to double the percent signs "%%" on the "%[fx:...]" expressions. Obviously if the tiled input images don't divide evenly into the output canvas size, the tiles won't be aligned in the result.

Rye
Posts: 156
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Repeat "multiple images" over fixed canvas size

Post by Rye » 2018-11-08T11:19:39-07:00

Sweet ! Works like a charm :).

Care to explain what exactly the ??? is standing for ? A place holder ?

Would it be possible to use a for loop instead of it, to avoid always having to use 000 - 0xx naming schemes ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC

User avatar
GeeMack
Posts: 645
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Repeat "multiple images" over fixed canvas size

Post by GeeMack » 2018-11-08T12:55:13-07:00

Rye wrote:
2018-11-08T11:19:39-07:00
Care to explain what exactly the ??? is standing for ? A place holder ?
In Windows BAT scripts and at the command line the question marks "?" are wildcards for individual characters, so "???.png" means any PNG image with a three character name.
Would it be possible to use a for loop instead of it, to avoid always having to use 000 - 0xx naming schemes ?
You could just run that single command using an asterisk wildcard instead of the question marks, like "*.png". That would read in all the PNG images in the directory regardless of name. That does what you want as long as they're in the order you like. The catch is it may also try to read the output file if it also has an extension of ".png". Get around that by reading your input files from another directory like "inputimages\*.png", or write your output file to another directory like "resultimage\tiled.png". If the command works to tile the images the way you want, I'm not sure there's a way to use a "for" loop to make it work any better.

kimmyk
Posts: 17
Joined: 2018-11-01T13:07:06-07:00
Authentication code: 1152

Re: Repeat "multiple images" over fixed canvas size

Post by kimmyk » 2018-11-08T14:27:37-07:00

@GeeMack: Awesome, was looking for something like this myself ;-)
Is it possible to:
1. set a min width in case there are less images to fill the canvas?
2. limit the amount of images for on the canvas (for digital coupon purposes where we increase the "stamp" by one each time
3. can we use the code between () so we can have a e.g. 600x300 pixel canvas inside a 1200x1200 image?

Thanks.

User avatar
GeeMack
Posts: 645
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Repeat "multiple images" over fixed canvas size

Post by GeeMack » 2018-11-08T20:00:21-07:00

kimmyk wrote:
2018-11-08T14:27:37-07:00
Is it possible to:
1. set a min width in case there are less images to fill the canvas?
2. limit the amount of images for on the canvas (for digital coupon purposes where we increase the "stamp" by one each time
The object of the OP's task is to repeat a series of input images until the canvas is filled. Setting a limit, although it certainly can be done, would require a somewhat different approach.
3. can we use the code between () so we can have a e.g. 600x300 pixel canvas inside a 1200x1200 image?
Sure. I have scripts with just single IM commands that build lots of separate parts inside dozens of parentheses, even nested parentheses, then assemble those parts inside yet more parentheses.

If you have something in particular in mind, maybe work up some simple examples and post some of your command ideas in a new thread. There's usually someone who can help point you in the right direction.

Post Reply