Hamza
Hamza

Reputation: 2413

ImageMagick - Merge and center multiple images

I am trying to append multiple PNG files, which are of different dimensions, into a single combined image.

I want individual 'layers' to be centered.

This is what I am trying to achieve in pictorial form:

.

A simple:

convert a.png b.png c.png -flatten combined.png

results in:

.

...and I was able to center everything by manually specifying offsets ('-page +X+Y') but I was wondering if there is an automatic way of achieving this.

Upvotes: 8

Views: 8148

Answers (2)

roslav
roslav

Reputation: 480

Better but still not the best solution because of temporary image:

composite -gravity center  b.png a.png temp.png \
&& \
composite -gravity center c.png temp.png composite.png

Upvotes: 6

Mark Setchell
Mark Setchell

Reputation: 208077

You can avoid the temporary file by compositing b.png onto a.png and then c.png on top of that like this:

convert -gravity center a.png b.png -composite c.png -composite result.png

enter image description here

Upvotes: 9

Related Questions