获取png图像的像素alpha值?

I am using the following code:

$img = imagecreatefrompng("image.png");
$col = imagecolorat($img, $x, $y);
$alpha = (($col >> 24) & 0x7F);

but the alpha value is always 127, even if the pixel at ($x,$y) is transparent in the original image.

ya you right , you may have confused with html canvas alpha ranges

when working on php side your alpha will be always 0 to 127 # 0 mean non transparent and 127 mean transparent

when working with front end HTML canvas your alpha range will be 0 to 255 # 0 mean Transparent & 255 mean non transparent