How it's possible to get the transparency value of a pixel on an image?
'imagecolorat' picks only the index of the color of the pixel at the specified location in the image. With that index I can get the RGB values but not the transparent one.
Hope you understand, an开发者_开发问答d thank you in advance.
the solution could be following:
$colorIndex = imagecolorat($img, $x, $y);
$colorInfo = imagecolorsforindex($img, $colorIndex);
print_r($colorInfo);
that will print something like:
Array
(
[red] => 226
[green] => 222
[blue] => 252
[alpha] => 0
)
where [alpha] is Your transparency value... (from 0 to 127 where 0 is totaly opaque and 127 is totaly transparent)
Enjoy!
As far as I know, the transparency value is returned by the function imagecolorat
. Could you try:
$color = imagecolorat($image, $x, $y);
$transparency = ($color >> 24) & 0x7F;
The transparency is a integer between 0 and 127 so we need to mask the first 8 bits of the 32bit color integer.
According to the PHP manual imagecolorat returns the index of the colour at the specified X/Y coordinates (i'm assuming this is for GIF and/or PNG-8).
If you know the index, then the problem is determining which index in the file is the transparent one.
imagecolortransparent might be worth looking at, imagecolorsforindex may also be helpful.
精彩评论