Just want to combine 2 images
Just want to combine 2 images
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
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
- 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
try
convert backgroundimage foregroundimage -gravity center -compose over -composite resultimage
see
http://www.imagemagick.org/Usage/layers/
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.
Re: Just want to combine 2 images
Wow thanks for the quick reply!
I get the error: mogrify.exe unrecognized option -compose
I get the error: mogrify.exe unrecognized option -compose
Re: Just want to combine 2 images
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".
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".
- 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
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
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
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.
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.
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Just want to combine 2 images
It is a problem with your quotes around the -draw arguments. Are you on Windows? Try swapping your use of single and double quotes.
- 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
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
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
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.
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
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!
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!
- 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
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.From the documentation, it seems composite should work..