murfy Posted February 21, 2014 Share Posted February 21, 2014 Is there a way to get alpha channel value with input values x,y into integer? Any method for high performance and without generating arrays? Also I want to ask you about the following command, which seems to be a mysthic for me. $rgb = imagecolorat($im, $x, $y); $c = imagecolorsforindex($im, $rgb); They used to use two commands to get array of rgba, instead one command that would return rgba type of integer... Why? Why so complicated? And also - it is not clear to me -> how can imagecolorsforindex() work when it misses the x, y values and $rgb misses x,y values too?! That makes no sense! But I would like to see some command to do it in the way like this: $rgba = imagecolorsat($im, $x, $y); $a = $rgb & 255; $b = ($rgb >> & 255; $g = ($rgb >> 16) & 255; $r = ($rgb >> 24) & 255; Without need to call two functions and generating arrays... Any better solutions? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 21, 2014 Share Posted February 21, 2014 You're asking if there's a way to get what you want except for the way you're supposed to use? imagecolorat() tells you the full RGBA value (truecolor) or color index (palette). imagecolorsforindex() converts both of those into a single r,g,b,a array without you having to care whether the image is truecolor or palette. $color = imagecolorat($im, $x, $y); $colorarray = imagecolorsforindex($im, $color); $alpha = $colorarray['alpha'];The imagecolorsforindex() call should be very fast: either it decomposes the AARRGGBB value (simple bit math = constant time) or it looks up the RGBA values in the image's color palette (array offset = constant time). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.