Jump to content

explanation needed for gd - to get alpha value directly


murfy

Recommended Posts

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?

Link to comment
Share on other sites

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).
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.