concatenating images of different size, with gap between,

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
abaabheejaa

concatenating images of different size, with gap between,

Post by abaabheejaa » 2010-06-09T02:45:00-07:00

Hi

I am trying to concatenate two images, which have different size (width), with a small gap between them (no border). I try the following:

montage palc3.tif dpac5.tif -geometry +1+0 -tile 2x1 -compress LZW concat.tif

However, the tile command seems to create two cells with the size of the larger image. Thus, there is a lot of space left around the smaller image in the concatenated file, as described in the documentation. What is a good way to get around this?? Earlier someone suggested using splice with convert, but -splice is not recognized by convert?

Sorry to start a new thread about this, but I thought this might be a useful reference.

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

Re: concatenating images of different size, with gap between

Post by snibgo » 2010-06-09T09:07:32-07:00

Suppose we have:

convert -size 100x100 xc:green g.png
convert -size 30x100 xc:blue b.png

We can put them side-by-side with no gap or border:

convert g.png b.png +append gb.png

We can do this with a 10-pixel red gap:

convert g.png b.png +append -background red -splice 10x0+100+0 gb.png
snibgo's IM pages: im.snibgo.com

User avatar
anthony
Posts: 8886
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: concatenating images of different size, with gap between

Post by anthony » 2010-06-14T23:28:33-07:00

snibgo wrote:We can do this with a 10-pixel red gap:

convert g.png b.png +append -background red -splice 10x0+100+0 gb.png
that requires you to know the size of the first image.

here is one that doesn't. It insearts a small red image, between the two images.

Code: Select all

convert g.png b.png  -size 10x10 xc:Red +swap \
            -gravity Center -background Red +append  gb.png
If you don't know how may images are involved the solution is to use splice
to prepend some space to ALL the images, then remove the first one from the result.

Code: Select all

convert g.png rose: granite: b.png \
            -background Red -splice 10x0+0+0 \
            -gravity Center +append \
            +gravity -chop 10x0+0+0    gb.png
Hmmm the above fails with the current version of IM!!!!!
It looks like the -splice is seeing the -gravity before it was set. Reporting.


This however is working as expected

Code: Select all

convert \( g.png rose: granite: b.png \
            -background Red -splice 10x0+0+0  \) \
            -gravity Center +append \
            +gravity -chop 10x0+0+0    gb.png
Of course rather than removing the leading 'red' spacing, you could just add another
bit of read spacing at the end...

Code: Select all

convert \( g.png rose: granite: b.png \
            -background Red -splice 10x0+0+0  \) \
            -gravity Center +append \
            -gravity SouthEast -splice 10x0+0+0    gb.png
NOTE: this is NOT the same as the spacing added by "montage". That command
first padds out all images to the 'cell' size. then add border around ALL the images
before appending.

That is to say it will add 10 pixels at the sides, and 20 pixels between the images.


For removing spacing from equal sized images see...
Separating Spaced-out Tiling Images
http://www.imagemagick.org/Usage/crop/#crop_spaced
this also explains the difference between the three 'standard' image spacing techniques.


This same technique is also used by a new IM Shell Script, Enlarge Images
http://www.imagemagick.org/Usage/scripts/enlarge_images
whish takes a small image and enlarges each pixel into a square, with space between.
A bit like what you were doing.

Example output is shown at the new IM example...
http://www.imagemagick.org/Usage/convolve/#life
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

Post Reply