Merge images ...

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
webid

Merge images ...

Post by webid »

Hi !

I'd like to merge an infinity of images with independant coordinates.

I tried with the next command :

Code: Select all

composite -geometry +50+150 image_1.png -geometry +100+200 image_2.png -geometry +150+250 image_3.png final.png
The result is very strange ... How I can get a good result ?

Thank's :)

ps : Sorry for my english, I hope you'll understand me ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Merge images ...

Post by fmw42 »

what is strange about it? you need to show us your result and explain why it is strange?

composite needs a background image to composite all the other over.

you probably really want -flatten, but then you need to change -geometry to -page

see
http://www.imagemagick.org/Usage/layers/#flatten

and in general the whole of
http://www.imagemagick.org/Usage/layers/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Merge images ...

Post by anthony »

composite will only deal with the merger of two images only though make have the help of a third masking image. That is it no more, no less.

The basic "convert -composite" method also only deals with two images only.

The other major technique is image 'layering'. using -flatten, -mosaic, and -layers merge. This can take any number of images BUT they are positioned using absolute virtual canvas offsets (no geometry or gravity).
http://www.imagemagick.org/Usage/layers/#flatten

These work by calculating an appropriate background canvas (how it is calculated depends on the operator) and then composing each image onto that canvas one compose at a time.

------------

However you said infinite!!!!!!. Well I doubt any computer can read an infinite number of images into memory as layers before being 'merged' or 'flattened' together. As such for an 'infinte' number of images you will need to read the image, merge, read the next image, merge, etc etc etc.

For methods to do this see the second before 'flatten' in IM Examples section 'layering images'. It shows, three methods, draw, compose, and convert multiple image composition. In each style shows methods of positioning and resizing images to fit the canvas.
http://www.imagemagick.org/Usage/layers/#composite

------------------

If your command line is getting too long (or 'infinite') then you will have to also start breaking up the sequences into multiple commands, saving the resulting intermediate image each time (with the input/Output cost involved). In that case you may also like to look at using MPC file format
http://www.imagemagick.org/Usage/files/#mpc

This still has a I/O cost, but it is just a memory dump and restore, without any image parsing or data processing, so the cost is fast. Also on Unix/Linux machines this is read in using memory mapped disk files, making it even faster for disk reading.

So for an infinite number, I would say read 10 to 100 images into memory, with positioning information, flatten, then dump to and MPC file. Then repeat with the next batch of images.

--------------------------------------------
THE FUTURE...

In ImageMagick version 7, it may be possible to run a 'convert' command as a 'daemon' process, feeling it a pipeline of command to process immediately they are seen. in this case you have not command line limits (a pipeline can be infinite), and the daemon convert command could hold the results in memory while reading in and positioning each image one at a time.

At the moment however "convert" is limited to command line options, as it parses those options twice as part of its syntax checking. It does not need to do this, but currently does due to historical and backward compatibility reasons. As such it cannot currently read processing options from a file or a pipeline :-(

See Considerations for changes in ImageMagick Version 7
http://www.imagemagick.org/Usage/bugs/I ... ations.txt
for more details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply