Page 1 of 2

centered append

Posted: 2008-11-30T17:50:05-07:00
by RetroJ
There may be a documentation bug at: http://imagemagick.org/Usage/montage/#append. It says the following:
Montage can use use for appending images with centering, without gaps between the images.

Code: Select all

montage -geometry '1x1+0+0<' -size 100x100 xc:red -size 30x30 xc:blue x:
Image

Montage does not introduce gaps between *tiles*, but it does introduce gaps between *images*, since all images are padded to make equal-sized tiles.

If I could add a quick feature request to this observation, I am looking for a concise way to get a result like the following:

Image

... a centered append of any number of images of different dimensions.

Thank you.

Re: centered append

Posted: 2008-11-30T18:46:02-07:00
by fmw42
This seems to work for me using the IM internal images so you can reproduce it.

montage logo: netscape: granite: rose: -background none -geometry +0+0 -gravity east -tile x1 tmp.png

this appends the images from left to right getting smaller as they go, with no space between, centered vertically and with transparent areas for fill.

This reproduces your image goal:

montage -size 100x100 xc:red -size 30x30 xc:blue -background none -geometry +0+0 -gravity east -tile x1 tmp.png

see all the details at http://www.imagemagick.org/Usage/montage/

Re: centered append

Posted: 2008-11-30T20:13:58-07:00
by RetroJ
fmw42 wrote:This reproduces your image goal:

montage -size 100x100 xc:red -size 30x30 xc:blue -background none -geometry +0+0 -gravity east -tile x1 tmp.png
Many thanks.

But now the question changes because this pattern does not seem applicable to achieve centered vertical appends:

Code: Select all

montage -size 100x100 xc:red -size 30x30 xc:blue -background none -geometry +0+0 -gravity south -tile 1x x:
Image

Re: centered append

Posted: 2008-11-30T21:51:41-07:00
by fmw42
Beats me! Perhaps my use of -gravity was a fluke that worked only in the horizontal mode. I cannot make it work in the vertical montage mode, either.

Trying

montage -size 100x100 xc:red -size 30x30 xc:blue \
-background none -geometry '1x1+0+0<' -tile 1x tmp.png


does center, but has a gap, contrary to what is explained at http://www.imagemagick.org/Usage/montage/#append


This appears to work, but has more transparent area below the blue, so the total image is too tall.

montage -size 100x100 xc:red -size 30x30 xc:blue \
-background none -gravity north -geometry '1x1+0+0<' -tile 1x tmp.png


This works, but is somewhat of a cludge. I added a transparent 1 pixel border then trimmed all the excess transparency out. But I had to use a pipe to get it to work.

montage -size 100x100 xc:red -size 30x30 xc:blue \
-background none -gravity north -geometry '1x1+0+0<' -tile 1x miff:- |\
convert - -bordercolor none -border 1 -trim \
tmp.png


Lets see what Anthony has to say. He would know best.

Re: centered append

Posted: 2008-12-01T00:06:47-07:00
by anthony
Montage is not a good way of doing this. basically it will fail is the image with the largest dimension is NOT first.

the better way is shown in IM Examples, Layering Images, Append.

Re: centered append

Posted: 2008-12-01T00:19:46-07:00
by fmw42
anthony wrote:Montage is not a good way of doing this. basically it will fail is the image with the largest dimension is NOT first.

the better way is shown in IM Examples, Layering Images, Append.
Anthony,

we are trying to understand why vertical montage with horizontal centering per your notes leaves gaps contrary to what you said at http://www.imagemagick.org/Usage/montage/#append

"Montage can use use for appending images with centering, without gaps between the images"

montage -size 100x100 xc:red -size 30x30 xc:blue \
-background none -geometry '1x1+0+0<' -tile 1x tmp.png

This leaves a gap.

But horizontal montaging works just fine per my example

montage -size 100x100 xc:red -size 30x30 xc:blue -background none -geometry +0+0 -gravity east -tile x1 tmp.png

Re: centered append

Posted: 2008-12-01T06:12:53-07:00
by RetroJ
fmw42 wrote:Perhaps my use of -gravity was a fluke that worked only in the horizontal mode.
That seems to be the case. Strictly speaking -gravity east was unnecessary in this example, but both north and south work as expected while tiling horizontally.
fmw42 wrote:we are trying to understand why vertical montage with horizontal centering per your notes leaves gaps contrary to what you said at http://www.imagemagick.org/Usage/montage/#append

"Montage can use use for appending images with centering, without gaps between the images"

montage -size 100x100 xc:red -size 30x30 xc:blue \
-background none -geometry '1x1+0+0<' -tile 1x tmp.png

This leaves a gap.

But horizontal montaging works just fine per my example

montage -size 100x100 xc:red -size 30x30 xc:blue -background none -geometry +0+0 -gravity east -tile x1 tmp.png
fmw42: The "without gaps" quote on the Usage page could certainly be better worded, but the source of those gaps is easy to understand: putting a width and height in the geometry (1x1+0+0<) sets the resize specification, thus forcing montage to create equal-size tiles. When the geometry is just +0+0, there is no resize spec, so montage does not create padded tiles.
anthony wrote:Montage is not a good way of doing this. basically it will fail is the image with the largest dimension is NOT first.

the better way is shown in IM Examples, Layering Images, Append.
These sound like challenging problems if imagemagick is to ever provide a concise syntax for performing this operation.

Re: centered append

Posted: 2008-12-01T20:03:09-07:00
by fmw42
Here is another way that works, but you need to know the sizes of the images and especially the largest one. The best way would be to write a script. I might try doing that, but in the meantime, here is an example for horizontal append with vertical centering:

convert \( -size 50x50 xc:green1 -gravity center -background none -extent 50x100 \) \
\( -size 100x100 xc:red \) \
\( -size 30x30 xc:blue -gravity center -background none -extent 30x100 \) \
+append tmp.png

Too bad that -extent does not let you do an extension in one dimension via something like -extent x100, where it knows to keep the other dimension unchanged. (I tried 0x100 that gave an error).

I see a note in the changelog that this may have been fixed in IM 6.4.6-6. So I am now upgrading to 6.4.6-8 and will report back.

Yes, it has been fixed. So in IM 6.4.6-8, if one knows the height of largest image, one can do:

convert -size 50x50 xc:green1 -size 100x100 xc:red -size 30x30 xc:blue \
-gravity center -background none -extent x100 \
+append tmp.png

and get center justified horizontal appending.





Here is a more general approach with a little shell code to append the three IM internal images (rose: netscape: and granite:). The shell code gets the max height of the images.

imglist="rose: netscape: granite:"
maxht=0
for img in $imglist; do
ht=`convert $img -format "%h" info:`
if [ $ht -gt $maxht ]; then
maxht=$ht
fi
done
convert $imglist -gravity center -background none -extent x${maxht} +append tmp1.png

Re: centered append

Posted: 2008-12-01T21:50:40-07:00
by anthony
RetroJ wrote:fmw42: The "without gaps" quote on the Usage page could certainly be better worded, but the source of those gaps is easy to understand: putting a width and height in the geometry (1x1+0+0<) sets the resize specification, thus forcing montage to create equal-size tiles. When the geometry is just +0+0, there is no resize spec, so montage does not create padded tiles.

These sound like challenging problems if imagemagick is to ever provide a concise syntax for performing this operation.
Using montage for append is NOT what it was designed to do. and it is only a fluke that it does something useful in this regard. Its primary purpose was a script that uses the Magick Core library to generate an array of image thumbnails, That is all.

Append and image array generation in various layouts is something that IM should have more development on. For example append justification, and methods to 'fill line-by-line to a certain width' a bit like 'caption:' does for words. Also other 'packing' styles of filling a page. See IM examples future proposals for ideas I have had for this.
http://www.imagemagick.org/Usage/bugs/future/#append
Included in this should be additional image comments or other meta-data detailing the final placement of the input images to allow later options to generate the html image maps.

The 'cell framing' aspect of "montage" should be merged into the core library (with options line 'polaroid' framing).

Basically more scope in image arrangements.

Re: centered append

Posted: 2008-12-01T21:53:11-07:00
by fmw42
It would be nice for future enhancement to make append sensitive to relevant -gravity settings.

Re: centered append

Posted: 2008-12-03T08:08:13-07:00
by RetroJ
anthony wrote:Append and image array generation in various layouts is something that IM should have more development on. For example append justification, and methods to 'fill line-by-line to a certain width' a bit like 'caption:' does for words. Also other 'packing' styles of filling a page. See IM examples future proposals for ideas I have had for this.
http://www.imagemagick.org/Usage/bugs/future/#append
Included in this should be additional image comments or other meta-data detailing the final placement of the input images to allow later options to generate the html image maps.

The 'cell framing' aspect of "montage" should be merged into the core library (with options line 'polaroid' framing).

Basically more scope in image arrangements.
Very cool ideas.

Re: centered append

Posted: 2008-12-03T08:09:47-07:00
by RetroJ
fmw42 wrote:Yes, it has been fixed. So in IM 6.4.6-8, if one knows the height of largest image, one can do:

convert -size 50x50 xc:green1 -size 100x100 xc:red -size 30x30 xc:blue \
-gravity center -background none -extent x100 \
+append tmp.png

and get center justified horizontal appending.
Excellent. Thank you.

Re: centered append

Posted: 2008-12-03T16:49:56-07:00
by anthony
Using -extent instead of -border is a better solution, one that was not available when I first wrote the examples for justified append.

However the better solution would be for -append to do this itself, as it has to cycle through the images anyway to determine the final image 'bounds' before composing the images into the final result.

As such I think it may be time to 'fix' -append to understand -gravity, and/or finally get a separation of -gravity and 'justification'.

Re: centered append

Posted: 2008-12-03T19:56:35-07:00
by magick
ImageMagick 6.4.7 has support for -gravity -append.

Re: centered append

Posted: 2008-12-03T20:58:58-07:00
by fmw42
I have posted a script, adjoin, to perform this action until -append is modified to be sensitive to -gravity

http://www.fmwconcepts.com/imagemagick/index.html