Page 1 of 1

tile with images that fits into specified witdh with space between them

Posted: 2017-02-17T09:23:24-07:00
by andrearastelli
Hi,

I can't find a solution to this problem:

I want to merge, horizontally, a bunch of images.

And this is easy:

Code: Select all

montage *.png -tile x1 output.png
But my goal would be that those tiled images will dispose automatically to fit a specified output image width (let's say 10000 pixel).
And, between each image, a transparent space needs to be leaved if the total width of all the images one next to the other is lower that the width of my specified output.

Do you think that this is something that can be done just by using ImageMagick?


Thanks


EDIT:

I've found this example:

Code: Select all

convert * -set page "+%%[fx:1200*cos((t/n)*2*pi)]+%%[fx:1200*sin((t/n)*2*pi)]" -layers merge +repage output.png
*the command is adapted to work in a DOS environment


Instead of generating a circe distribution of images.. maybe this is the way to obtain what I need...

Re: tile with images that fits into specified witdh with space between them

Posted: 2017-02-17T09:39:14-07:00
by snibgo
One method: subtract the total width of the images from 10000. Divide this by twice the number of images. If that result is N, use it in "-geometry +N+0".

Re: tile with images that fits into specified witdh with space between them

Posted: 2017-02-17T10:06:33-07:00
by andrearastelli
Ok, now the hard part is to tell DOS to do the proper math...

Code: Select all

montage *.png -tile x1 -geometry +%size%+0 output.png
Thanks!!!

Re: tile with images that fits into specified witdh with space between them

Posted: 2017-02-17T10:19:26-07:00
by snibgo
It could be something like this, using three rose images as examples, and a required width of 1000. Windows BAT syntax.

Code: Select all

set NUM_IMG=3
set WIDTH=1000

for /F "usebackq" %%L in (`%IM%montage ^
  rose: rose: rose: -geometry +0+0 -background None ^
  -format "EXTRA=%%[fx:(%WIDTH%-w)/(2*%NUM_IMG%)]" ^
  info:`) do set %%L

echo EXTRA=%EXTRA%

%IM%montage ^
  rose: rose: rose: -geometry +%EXTRA%+0 -background Red ^
  x.png
EXTRA is a floating-point number, and the resulting width may not be exactly 1000. You might use:

Code: Select all

  -format "EXTRA=%%[fx:int((%WIDTH%-w)/(2*%NUM_IMG%)+0.5)]"
... then use "-extent" to make it exactly 1000.

I use "Red" for testing. Change to "None" when it does what you want.