how do I put 2 pictures together?

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
metalbear
Posts: 5
Joined: 2018-12-02T08:19:37-07:00
Authentication code: 1152

how do I put 2 pictures together?

Post by metalbear » 2018-12-02T08:30:14-07:00

Hello everybody!
I need help to put two pictures together in a batch processing unit.
The files have the same name and are stored in different directories.
The picture in directory A is 3600x2400 pixel
The picture in directory B is 1683x1274 pixel
The image in directory B should be placed on the image in directory A, with the upper left corner on pixel X: 638 and Y: 584.
And the whole as a batch for over 500 files, consecutively numbered.
I work in a windows environment.
Can someone write me the appropriate command line?
Thank you very much!

metalbear
Posts: 5
Joined: 2018-12-02T08:19:37-07:00
Authentication code: 1152

Re: how do I put 2 pictures together?

Post by metalbear » 2018-12-02T09:12:11-07:00

Alternatively, the images in directory B could be available in the same size as directory A, but only a specific section of image B should be inserted.

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

Re: how do I put 2 pictures together?

Post by snibgo » 2018-12-02T09:39:56-07:00

What version of IM? I'll assume v7.

First steps first, which is the image processing. You want to composite one image over another, at a certain offset. Worry about the loop later.

Code: Select all

magick imageB.png imageA.png -geometry +638+584 -composite out.png
Does that do what you want?

For your extra question, you might need a test on whether the imageB is the same size as imageA, then do:

Code: Select all

magick ( imageB.png -crop {something} +repage ) imageA.png -geometry +638+584 -composite out.png
snibgo's IM pages: im.snibgo.com

metalbear
Posts: 5
Joined: 2018-12-02T08:19:37-07:00
Authentication code: 1152

Re: how do I put 2 pictures together?

Post by metalbear » 2018-12-02T10:34:14-07:00

Thank you very much for your answer.
Your first code does exactly what I need.

Can you also tell me how to build a loop?

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

Re: how do I put 2 pictures together?

Post by snibgo » 2018-12-02T11:45:45-07:00

I would use a "for" loop, like this:

Code: Select all

for /F %F in (directoryA\*) do magick directoryB\%F directoryA\%%F -geometry +638+584 -composite outdir\%F
For help on "for", type "for /?".

If using in a BAT script, double the percentage signs.
snibgo's IM pages: im.snibgo.com

metalbear
Posts: 5
Joined: 2018-12-02T08:19:37-07:00
Authentication code: 1152

Re: how do I put 2 pictures together?

Post by metalbear » 2018-12-02T12:52:40-07:00

Good evening.
Thanks again for your answers.
I use Windows10 as OS, magick-version = 7.0.8-15

I tried your for-loop in a BAT script, ends in error file cant be found.

Code: Select all

for /F %%F in (.\GreenScreen\umbenannt\*) do magick .\GreenScreen\umbenannt\%%F .\Originals_klein\Ausschnitt\umbenannt\%%F -geometry +638+584 -composite .\NEU\%%F
Die Datei ".\GreenScreen\umbenannt\*" kann nicht gefunden werden.
I tried to google it, this happens because /F cant be used with a wildcard.

Then i tried without /F :
D:\Bilder\2018\Hochzeit_dslrbooth>magick .\GreenScreen\umbenannt\.\GreenScreen\umbenannt\515.jpg .\Originals_klein\Ausschnitt\umbenannt\.\GreenScreen\umbenannt\515.jpg -geometry +638+584 -composite .\NEU\.\GreenScreen\umbenannt\515.jpg
magick: unable to open image '.\GreenScreen\umbenannt\.\GreenScreen\umbenannt\515.jpg': No such file or directory @ error/blob.c/OpenBlob/3490.
There´s a problem with %F, it shows always the full directory, not only the filename.

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

Re: how do I put 2 pictures together?

Post by snibgo » 2018-12-02T13:02:21-07:00

Sorry, yes, remove "/F", and use "%~nxF".
snibgo's IM pages: im.snibgo.com

metalbear
Posts: 5
Joined: 2018-12-02T08:19:37-07:00
Authentication code: 1152

Re: how do I put 2 pictures together?

Post by metalbear » 2018-12-03T11:39:12-07:00

Thats it! Thank you very much for your great support!

Post Reply