composite a png with alpha layer and a BMP background

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
tonic8
Posts: 2
Joined: 2012-01-30T13:47:20-07:00
Authentication code: 8675308

composite a png with alpha layer and a BMP background

Post by tonic8 »

Hello

i need to add a marketing logo to the wallpaper of windows desktop. So i'm working on a script and i found the imagemagick tool kit.

That seems to be VERY powerfull. I had successfully merged 2 simples pictures

but now i'm trying to merge 2 pictures with a transparent layer
the background and main picture is a bmp (current wallpaper on windows) (named a.bmp)
the logo to be added is a png with a transparent zone (square picture containing a round logo, all arround the logo is transparent color) (named b.png)

when using compositing, i failed... So i'm trying to force marketing to change the logo to square form :-) But if you could help me...

Thanks you...
Tonic8
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: composite a png with alpha layer and a BMP background

Post by Bonzo »

I can get it to work OK and you need to supply more information:

What does not work
What code are you using
What version of IM are you using
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: composite a png with alpha layer and a BMP background

Post by glennrp »

You could use the -draw option

Code: Select all

 convert a.bmp -draw "image over x,y 0,0 b.png" result.png
If b.png is as you describe opaque with a central logo surrounded
by a background color, then give it transparency first (replace #FFFFFF
with whatever your background color is):

Code: Select all

convert b.png -transparent "#FFFFFF" -matte c.png
convert a.bmp -draw "image over x,y 0,0 c.png" result.png
or result.bmp if you need the output in BMP format.
tonic8
Posts: 2
Joined: 2012-01-30T13:47:20-07:00
Authentication code: 8675308

Re: composite a png with alpha layer and a BMP background

Post by tonic8 »

hello sorry for the missing points here are the command line a i used

composite.exe -gravity south -geometry +20+20 -alpha Background "toto.png" "wallpaper.bmp" "newWallpaper.bmp"

i use composite because i need to choose the position inside the wallpaper (a leasr depending on people there will hae 2 logo inserted, not a the same position)

but meanwhile i have found why is not working, the alpha layer was not correctly set by the graphist, using a one i created for the purpose it work fine...

i will kick the ass of the graphist :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite a png with alpha layer and a BMP background

Post by anthony »

the -alpha background is not needed! It sets the hidden color of the transparent pixels, which is irrelevent and ignored by the composition operation. Transparent pixels are transparent, and the hidden color is not used.

What were you trying to do by adding that operation?

Also you can position the image using "convert", (and do many other things too if you later want). The syntax is just a little different or "composite", (image order and use of -composite image operator) but you can find it described on
http://www.imagemagick.org/Usage/compose/#compose

This should do what you want...

Code: Select all

convert "wallpaper.bmp" "toto.png" -geometry +20+20 -gravity South -composite "newWallpaper.bmp"
More examples of thsi is in..
Annotating Images (which is what you are doing), positioning images with gravity...
http://www.imagemagick.org/Usage/annota ... ge_gravity
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite a png with alpha layer and a BMP background

Post by fmw42 »

Also see http://www.imagemagick.org/Usage/layers/ for different ways to overlay one or more images onto another or background.
Post Reply