Page 1 of 1

Just want to combine 2 images

Posted: 2013-08-03T17:51:54-07:00
by aaron
Hi guys,

I'm having trouble with a very simple action - I have a png w/transparent background that I want to place on top of another image to use as the background. The background image is slightly bigger, so I'd need to center it (using gravity?), but for now I was just trying to get a merged image with no luck.

When I run this command, ImageMagick crashes:
mogrify -composite -geometry +50+50 bg.png transparent0.png test.png

bg.png is my background image.
transparent0.png is my png w/transparent background
test.png is my desired output file

Also in the long run, I'd be creating the transparent png from a dds - then creating this new image with the png merged onto the background image.

I found tons of examples doing all kinds of crazy stuff, but nothing for this simple use case. Should I even be using composite? I tried flatten but that didnt do anything.

I need to use mogrify because once I get this working it will be applied to batches.

Thanks!

Aaron

Re: Just want to combine 2 images

Posted: 2013-08-03T17:56:06-07:00
by fmw42
try

convert backgroundimage foregroundimage -gravity center -compose over -composite resultimage

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

Re: Just want to combine 2 images

Posted: 2013-08-03T18:07:24-07:00
by aaron
Wow thanks for the quick reply!

I get the error: mogrify.exe unrecognized option -compose

Re: Just want to combine 2 images

Posted: 2013-08-03T18:48:29-07:00
by glennrp
Hmm, the documentation claims that the "-compose operator" option is available to "mogrify". I verified that I too get the error message.
Is either the foreground image or the background image the same for all pairs of images in your batch? If so it may be possible to use
mogrify with the "-draw image" option. I know that the "-draw" option is available to "mogrify".

Re: Just want to combine 2 images

Posted: 2013-08-03T19:06:19-07:00
by fmw42
I suspect that the documents for mogrify are wrong about -compose ... -composite. Mogrify only processes one image at a time, with the exception of using -draw to overlay one other same image on all the input images.

If you just want to overlay one image onto one other, then use the convert syntax I mentioned above.

If you want to overlay one common image on a set of images, then use mogrify and the syntax descripted at

http://www.imagemagick.org/Usage/basics ... fy_compose

just replace Dst_In with Over

mogrify -gravity center -draw 'image Over 0,0 0,0 "overlay.gif"' *.gif

change the suffix as desired. Also best to put all the output images into another directory using the -path option, see
http://www.imagemagick.org/Usage/basics/#mogrify

Re: Just want to combine 2 images

Posted: 2013-08-03T21:47:51-07:00
by aaron
Thanks again.

I tried to run:
mogrify -gravity center -draw 'image Over 0,0,0,0 "transparent0.png"' *.jpg

and got these errors:
mogrify.exe: unable to open image `Over': No such file or directory @ error/blob.c/OpenBlob/2643.mogrify.exe: no decode delegate for this image format `Over' @ error/constitute.
c/ReadImage/552.mogrify.exe: unable to open image `0,0,0,0': No such file or directory @ error/blob.c/OpenBlob/2643.
mogrify.exe: no decode delegate for this image format `0,0,0,0' @ error/constitute.c/ReadImage/552.
mogrify.exe: unable to open image `transparent0.png'': No such file or directory @ error/blob.c/OpenBlob/2643.mogrify.exe: no decode delegate for this image format `transparent0.png'' @ error/constitute.c/ReadImage/552.mogrify.exe: Non-conforming drawing primitive definition `image' @ error/draw.c/
DrawImage/3154.

Re: Just want to combine 2 images

Posted: 2013-08-03T21:57:47-07:00
by GreenKoopa
It is a problem with your quotes around the -draw arguments. Are you on Windows? Try swapping your use of single and double quotes.

Re: Just want to combine 2 images

Posted: 2013-08-03T22:11:01-07:00
by fmw42
This command works fine for me.

I put 3 copies of logo: -> logoX.png ( X=1,2,3) into test1 directory and put binaryimage2.png in the directory above test1. Then I created a new directory test2.


cd test1
mogrify -path ../test2 -format png -gravity center -draw "image over 0,0 0,0 '../binaryimage2.png'" *.png


Worked fine for me under IM 6.8.6.7 Q16 Mac OSX

Note you have 0,0,0,0 and it should be 0,0 0,0

Re: Just want to combine 2 images

Posted: 2013-08-03T22:36:36-07:00
by aaron
From the documentation, it seems composite should work..

But when I tried:
mogrify -layers composite -gravity center transparent0.png null: bg.png

I got this error:
mogrify.exe: Missing Null Image List Separator layers Composite @ error/mogrify.c/MogrifyImageList/8000.

Re: Just want to combine 2 images

Posted: 2013-08-03T22:39:39-07:00
by aaron
O M G. You guys are exactly right. I was able to create a combined image with this command:
mogrify -gravity center -draw "image Over 0,0 0,0 'transparent0.png'" *.jpg

Where transparent0.png is my background image that I want to apply.

Yes, I'm on Windows.

THANKS SO MUCH!

Re: Just want to combine 2 images

Posted: 2013-08-03T23:00:12-07:00
by fmw42
From the documentation, it seems composite should work..
I believe that the documentation is in error in that regard. The draw method is the only method I know that will overlay an image using mogrify.