Page 1 of 1

[SOLVED] Replace existing colour with a transparent colour

Posted: 2017-08-22T16:00:15-07:00
by gubi
Hi all,
I have a transparent png file and I want to replace an existing opaque colour (eg. #000) with a transparent rgba colour (eg. rgba(255, 0, 0, 50.0)). Is it possible?
I spent days without result.
Here the command I use:

Code: Select all

convert -fuzz 100% img_black.png -alpha on -fill 'rgba(255, 0, 0, 50.0)' -opaque '#000' image_red.png
Please, anyone can help me?
Thanks in advance

Re: Replace existing colour with a transparent colour

Posted: 2017-08-22T18:31:31-07:00
by fmw42
try reading the input first, then use opaque black. Also alpha is specified in the range of 0 to 1, not 0 to 100 or 0 to 255. So if you want 50% transparent use 0.5

Code: Select all

convert img_black.png -fuzz 100% -alpha on -fill 'rgba(255, 0, 0, 0.5)' -opaque '#000' image_red.png
or if that does not work, then

Code: Select all

convert img_black.png -fuzz 100% -alpha on -fill 'rgba(255,0,0,0.5)' -opaque '#000000FF' image_red.png
Please always provide your IM version and platform when asking questions on this forum.

Re: Replace existing colour with a transparent colour

Posted: 2017-08-23T02:44:28-07:00
by gubi
Hi,
thanks for your reply.
First of all, sorry for my forgetfulness.

Code: Select all

$ convert -version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib
My OS is Ubuntu Linux 16.04

I tried your commands simply by copy-paste but without success.
This is the black image:
Image

This is the output of the fist command:

Code: Select all

convert img_black.png -fuzz 100% -alpha on -fill 'rgba(255, 0, 0, 0.5)' -opaque '#000' image_red.png
Image

And this is the output of the second command:

Code: Select all

convert img_black.png -fuzz 100% -alpha on -fill 'rgba(255,0,0,0.5)' -opaque '#000000FF' image_red.png
Image

I expecting something like this:
Image

Important: I opened the output image with Gimp and the color profile is "indexed...". Is it possible to assign an RGB color profile to the output?

Thanks

Re: Replace existing colour with a transparent colour

Posted: 2017-08-23T11:19:10-07:00
by fmw42
Your image is totally black with a binary alpha channel. So one way is to make it totally red with an alpha channel reduced by 50%. This works for me on IM 6.9.9.8 Q16 Mac OSX. Change my path to your path to your sRGB.icc profile

Code: Select all

convert img_black.png -alpha off -fill red -opaque black -alpha on -channel a -evaluate multiply 0.5 +channel -profile /Users/fred/images/profiles/sRGB.icc image_red_half_alpha.png
Image

This also works. Add -channel rgba from my earlier suggested command.

Code: Select all

convert img_black.png -alpha on -channel rgba -fill 'rgba(255,0,0,0.5)' -opaque '#000000FF' -profile /Users/fred/images/profiles/sRGB.icc image_red_half_alpha.png

Re: Replace existing colour with a transparent colour

Posted: 2017-08-23T13:51:57-07:00
by gubi
Thanks!
The first command works as well.
The colour profile is downloadable from here: http://archive.ubuntu.com/ubuntu/pool/m ... ig.tar.bz2

Thanks a lot.
Gubi