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

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
andrearastelli
Posts: 2
Joined: 2017-02-17T09:15:43-07:00
Authentication code: 1151

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

Post by andrearastelli » 2017-02-17T09:23:24-07:00

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...

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

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

Post by snibgo » 2017-02-17T09:39:14-07:00

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".
snibgo's IM pages: im.snibgo.com

andrearastelli
Posts: 2
Joined: 2017-02-17T09:15:43-07:00
Authentication code: 1151

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

Post by andrearastelli » 2017-02-17T10:06:33-07:00

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!!!

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

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

Post by snibgo » 2017-02-17T10:19:26-07:00

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.
snibgo's IM pages: im.snibgo.com

Post Reply