The Little Guy Posted April 25, 2012 Share Posted April 25, 2012 I can not remember how to do this, so any help would be great! I am getting an alpha value from a pixel between 1 and 127, I need to convert it to a number between 1 and 0. 0 = 127 1 = 0 If you can help me remember the math to do this, it is very much appreciated! Link to comment https://forums.phpfreaks.com/topic/261570-ratios/ Share on other sites More sharing options...
Zane Posted April 25, 2012 Share Posted April 25, 2012 If 127 is the highest value possible, then it would be division as simple as pixel value / 127 Link to comment https://forums.phpfreaks.com/topic/261570-ratios/#findComment-1340353 Share on other sites More sharing options...
The Little Guy Posted April 25, 2012 Author Share Posted April 25, 2012 Okay, that works, but how would you make: 127 / 127 = 0 and 0 / 127 = 1 and everything else in between (.5 = .5, .4 = .6, .3 = .7, etc.)? Link to comment https://forums.phpfreaks.com/topic/261570-ratios/#findComment-1340403 Share on other sites More sharing options...
Jessica Posted April 25, 2012 Share Posted April 25, 2012 .... subtract it from 1? Link to comment https://forums.phpfreaks.com/topic/261570-ratios/#findComment-1340404 Share on other sites More sharing options...
The Little Guy Posted April 25, 2012 Author Share Posted April 25, 2012 ah... Needed to do this: $a = abs(($a / 127) - 1); // $a = alpha Thanks guys/gals! This makes me feel dumb Link to comment https://forums.phpfreaks.com/topic/261570-ratios/#findComment-1340426 Share on other sites More sharing options...
kicken Posted April 25, 2012 Share Posted April 25, 2012 You could just do: $a = 1-($pixel/127); And not have to bother with abs(). Not that it really matters too much. Link to comment https://forums.phpfreaks.com/topic/261570-ratios/#findComment-1340522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.