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.
how to change the transparency(opacity) of an image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how to change the transparency(opacity) of an image
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.
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
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 but it didnt change anything. I also set the opacity by but it didnt help either..hope it is clear now, thanks for your interest.
Code: Select all
int alpha = getThreshold(); Color c(0,0,0,alpha); image.backgroundColor(c);
Code: Select all
int c = getThreshold(); image.opacity(c);
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how to change the transparency(opacity) of an image
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
I want to set the channel to same value.
Thanks.
Thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how to change the transparency(opacity) of an image
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.
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
Thanks..
anybody to offer a solution using magick++ ?
Best.
anybody to offer a solution using magick++ ?
Best.