Center Images next to each other

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
utbl
Posts: 18
Joined: 2016-09-22T01:53:33-07:00
Authentication code: 1151

Center Images next to each other

Post by utbl » 2016-11-22T02:36:40-07:00

I have following command:

convert -background none -bordercolor none -gravity west -fill white img1.png label:"1" -border 0x5 +swap -append label:"Kapitel 1" -border 0x5 -append -write miff:- +delete img2.png label:"2" -border 0x5 +swap -append label:"Kapitel 2" -border 0x5 -append -write miff:- +delete img3.png label:"3" -border 0x5 +swap -append label:"Kapitel 3" -border 0x5 -append -write miff:- +delete img4.png label:"4" -border 0x5 +swap -append label:"Kapitel 4" -border 0x5 -append -write miff:- +delete img5.png label:"5" -border 0x5 +swap -append label:"Kapitel 5" -border 0x5 -append miff:- | montage -set label "" miff:- -tile 3x2 -geometry +15-10 -background none result

which creates me an image with 5 image, each image has a text above and under.

The first 3 images above are "centered", but the last 2 images are not centered, how can I center so to say the last 2 image?

If I pick for instance 6 images everything looks fine, but I have to have an option for 1,2,3,4 and 5 images aswell and center them (horizontal and vertical)

How do I achieve this

User avatar
fmw42
Posts: 25654
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Images next to each other

Post by fmw42 » 2016-11-22T10:46:38-07:00

Can you provide both your input and output images so we can see what is happening. Also please also provide your IM version and platform whenever you ask questions, since syntax may differ. You can upload to some place such as dropbox.com and put the URLs here.

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Center Images next to each other

Post by glennrp » 2016-11-22T16:14:51-07:00

The "montage" utility doesn't have the capability you want. You'll need to make two separate montages, one for each row, and extend any 1- or 2-image row to full width, then use "convert -append" or "magick -append" to put the rows together.

For greater control over the layout (but more work for you), you can use "magick" or "convert" with the "-mosaic" option or a series of "-draw image over ..." operations.

Post Reply