centered append

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?".
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

centered append

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post 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/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: centered append

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: centered append

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post 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
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: centered append

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: centered append

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post by fmw42 »

It would be nice for future enhancement to make append sensitive to relevant -gravity settings.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: centered append

Post 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.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: centered append

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: centered append

Post 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'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: centered append

Post by magick »

ImageMagick 6.4.7 has support for -gravity -append.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: centered append

Post 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
Post Reply