Page 1 of 1

how to change the opacity value of a png file?

Posted: 2011-10-19T21:23:58-07:00
by linjuming
Image

Re: how to change the opacity value of a png file?

Posted: 2011-10-19T21:31:18-07:00
by fmw42
Please provide a link to the image you want to change? I don't know if you are trying to change a constant opacity in the image or a gradient opacity in the image? Please clarify.

see transparent canvas at http://www.imagemagick.org/Usage/canvas/#other

especially

convert test.png -matte -channel A -evaluate set 0 +channel trans_evaluate.png


change the set value to some value between 0 and 1

Re: how to change the opacity value of a png file?

Posted: 2011-10-19T21:45:48-07:00
by fmw42
if this is to change a gradient transparency from 0-100% to 0-70%, then try

convert test.png -matte -channel A +level 0,70% +channel trans_evaluate.png

if this is the wrong way opacity vs transparency, then use +level 30,100%

Re: how to change the opacity value of a png file?

Posted: 2011-10-19T21:54:52-07:00
by linjuming
original png
Image

code:

Code: Select all

<?php
	exec("convert opacity.png -matte -channel A -evaluate set 0.5 +channel laji.png");
	echo "<img src='opacity.png'/>";
	echo "<img src='laji.png'/>";

?>
<style type="text/css">
	html{background-color:gray;}
</style>
preview in firefox
Image

why the png is completly transparent ?

Re: how to change the opacity value of a png file?

Posted: 2011-10-19T22:18:50-07:00
by linjuming
not to change the contract , I only want to chage the png's opacity ,from 100% to 74% ,such as what i showed in photoshop above .but your code output a completly transparent png . Why?

Re: how to change the opacity value of a png file?

Posted: 2011-10-20T00:54:43-07:00
by anthony
I'm suprised there isn't a broken image!

Can the PHP write in that directory. is there a transparent image in that directory that is not writable by the PHP?

Better to check these thing without the complication of web page processing.

Re: how to change the opacity value of a png file?

Posted: 2011-10-20T09:43:08-07:00
by fmw42
please provide a link to your png image (not in a screen snap) so we can see what is really happening.

Re: how to change the opacity value of a png file?

Posted: 2011-10-20T10:23:25-07:00
by linjuming

Re: how to change the opacity value of a png file?

Posted: 2011-10-20T13:57:07-07:00
by fmw42
Your png file is composed of a white base image and a gradient alpha channel. So there is no one alpha value in that file. So what is that you want to do. If you make the opacity/transparency a constant, then you will lose your gradient.

To see this, look at the results of:

convert opacity-2.png -alpha off opacity-2_aoff.png
convert opacity-2.png -alpha extract opacity-2_alpha.pn



You would be better making a gradient base image and then making the alpha channel some constant say 70% as was describe above.

Try this:

convert -size 128x128 gradient: -matte -channel A -evaluate set 70% -channel rgba tmp.png

or

convert -size 128x128 gradient: -matte -channel A -evaluate set 30% -channel rgba tmp.png


Not sure which way you want it.

Re: how to change the opacity value of a png file?

Posted: 2011-10-20T19:23:26-07:00
by linjuming
Thank you , it helps