Page 1 of 1
how to change the transparency(opacity) of an image
Posted: 2010-04-02T00:37:53-07:00
by hakiim35
Hello, I have a png image and I want to change its alpha channel transparency.
There are some functions such as opacity(), backgroundColor(), transparent(), etc.
Suppose that I m receiving the transparency threshold(0-255) from the user in runtime.
Which one to use and how? should I write the image to a Blob and read back again to Image so that the change applies in runtime?
Best.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-02T09:27:03-07:00
by fmw42
need more information about what is in the alpha channel and how you want to change it.
basically extract the alpha channel (-alpha extract), modify it, then reattach it (-compose copy_opacity -composite)
There are other ways to do it all in one command line, but I need to know more about what you are doing.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-02T11:07:20-07:00
by hakiim35
I am developing an image processing tool that allows users to read/manipulate different image formats and set/change the attributes of them. I am using magick++ api, so command line processing is not the way I need. Basically, I want to enable the user to change the transparency of a png file. I tried setting the background attribute by
Code: Select all
int alpha = getThreshold(); Color c(0,0,0,alpha); image.backgroundColor(c);
but it didnt change anything. I also set the opacity by
Code: Select all
int c = getThreshold(); image.opacity(c);
but it didnt help either..hope it is clear now, thanks for your interest.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-02T11:54:42-07:00
by fmw42
I don't use API, only command line. But you have not said how you want to change the transparency. Do you want to set the whole channel to the same value or something else.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-02T12:48:05-07:00
by hakiim35
I want to set the channel to same value.
Thanks.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-02T15:27:43-07:00
by fmw42
In command line it could be done as either
convert zelda3.png -alpha on -channel A -evaluate set 25% +channel tmp2.png
or
convert image.png \( +clone -fill "gray(25%)" -colorize 100 \) -alpha off -compose copy_opacity -composite tmp3.png
This sets the opacity to 25% (transparency to 75%). So it is mostly transparent.
Sorry I don't know how to do it in any API.
Re: how to change the transparency(opacity) of an image
Posted: 2010-04-03T13:47:46-07:00
by hakiim35
Thanks..
anybody to offer a solution using magick++ ?
Best.