Just want to combine 2 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
aaron
Posts: 8
Joined: 2013-07-01T18:08:35-07:00
Authentication code: 6789

Just want to combine 2 images

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Just want to combine 2 images

Post by fmw42 »

try

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

see
http://www.imagemagick.org/Usage/layers/
Last edited by fmw42 on 2013-08-03T19:00:27-07:00, edited 1 time in total.
aaron
Posts: 8
Joined: 2013-07-01T18:08:35-07:00
Authentication code: 6789

Re: Just want to combine 2 images

Post by aaron »

Wow thanks for the quick reply!

I get the error: mogrify.exe unrecognized option -compose
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Just want to combine 2 images

Post 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".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Just want to combine 2 images

Post 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
aaron
Posts: 8
Joined: 2013-07-01T18:08:35-07:00
Authentication code: 6789

Re: Just want to combine 2 images

Post 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.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Just want to combine 2 images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Just want to combine 2 images

Post 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
aaron
Posts: 8
Joined: 2013-07-01T18:08:35-07:00
Authentication code: 6789

Re: Just want to combine 2 images

Post 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.
aaron
Posts: 8
Joined: 2013-07-01T18:08:35-07:00
Authentication code: 6789

Re: Just want to combine 2 images

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Just want to combine 2 images

Post 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.
Post Reply