I am trying to get the transparency from RGBA and convert it to CSS opacity.
So after getting the RGBA of an image pixel using the following:
$rgb = imagecolorat($img, $j, $i);
$colors = imagecolorsforindex($img, $rgb);
// Printing colors, I get
// 255,255,255,127
// 249,161,66,126
//...
For some reason, the transparency is always an integer (i.e. 127) and not a decimal number. But I want to convert that 127 figure to something I can use in CSS:
opacity:0;filter:alpha(opacity=0)
However, I can't work out the link between alpha in RGBA and how I can turn it into CSS opacity.
I will be doing this for all sorts of pixels from different types of images. PNG, JPG, GIF
Any ideas?
opacity = (127 - transparency) / 127.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With