0

I'm trying to do something very simple but somehow can't manage to do it.

I have an PNG with transparent areas.

How to add a background layer filled with some RGBA color such as rgba(255,0,0,128)?

I'm using imagemagick version 6 in its command line form.

This would be the PNG image for example: enter image description here

2 Answers 2

2

You can do that in ImageMagick by flattening the image against a color.

convert sayduck.png -background "rgba(255,0,0,0.5)" -flatten result.png 


enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Hum actually, not really. If you see, now the background isn't rgba(255,0,0,128) but rgba(255,0,0,255). We lost the transparency of it.
Same mistake as emcconville - used your values without thinking about how alpha is specified in ImageMagick. Need to change alpha in rgba from 128 to 0.5. Corrected now.
thanks ... I had it all along, did not realise the alpha chanel
1

First thing I can think of is to draw the color and composite under the image.

convert input.png \( +clone -fill 'rgba(255,0,0,0.5)' -draw 'color 0,0 reset' \) +swap -composite output.png 

output.png

Although I'm sure there's quicker ways.

1 Comment

Same than the answer bellow: If you see, now the background isn't rgba(255,0,0,128) but rgba(255,0,0,255). We lost the transparency of it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.