Page 1 of 1

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

Posted: 2018-11-07T11:55:22-07:00
by Rye
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)

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T12:09:57-07:00
by snibgo

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T12:48:27-07:00
by Rye
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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T13:19:23-07:00
by snibgo
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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T13:43:27-07:00
by Rye
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

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T16:01:20-07:00
by fmw42
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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-07T23:20:23-07:00
by GeeMack
Rye wrote: 2018-11-07T13:43:27-07:00For 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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-08T11:19:39-07:00
by Rye
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 ?

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-08T12:55:13-07:00
by GeeMack
Rye wrote: 2018-11-08T11:19:39-07:00Care 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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-08T14:27:37-07:00
by kimmyk
@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.

Re: Repeat "multiple images" over fixed canvas size

Posted: 2018-11-08T20:00:21-07:00
by GeeMack
kimmyk wrote: 2018-11-08T14:27:37-07:00Is 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.