Changing a transaparent background to a fixed colour

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
IBeaumont

Changing a transaparent background to a fixed colour

Post by IBeaumont »

Hi,
I've got a PNG with a transaparent background. I want to put the image onto a sold whitebackground. Currently I use GIMP to a white layer and then merge the layers down. I can't seem to come up with a way to do this in ImageMagick.
Something simple like:
convert -quality 75 -background #ffffff test_image.png new_image.jpg

doesn't do the job, it always ends up on a black background.

Image

TIA
Ian
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Changing a transaparent background to a fixed colour

Post by Bonzo »

If using a 6+ version of IM read your image in first. This should do what you want:

Code: Select all

convert test_image.png -fill red -opaque transparent -quality 75 new_image.jpg
IBeaumont

Re: Changing a transaparent background to a fixed colour

Post by IBeaumont »

Thanks - that sort of works, but looks awful. I think the issue is with semi-transparent pixels.

I have however just found a solution,

Code: Select all

convert -page +0+0 test.png  -background #ffffff -layers merge output.jpg
Thanks for the reply.
Post Reply