'imagecolorat' and transparency

扶醉桌前 提交于 2019-12-04 04:59:51

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.

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!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!