Perl GD Check If Pixel is Transparent

耗尽温柔 提交于 2019-12-06 15:48:43
DanielLazarov

I found a solution that seems to work properly:

my $index = $myImage->getPixel($x,y); 

will return a colour palette. The color palette's range depends on the mode, the image is open in. If it is TrueColor(24-bit RGB-16,777,216 colors), which is the maximum amount of colours recognisable by the human eye and the maximum colours practically used, the maximum palette number will be 16,777,215. When the function is called on a "transparent" pixel, the number returned is over 2 billion which is an invalid number for a 24-bit RGB colour. So one simple check:

if ($index >= 1<<24) {
    #The pixel is transparent
}

did the trick for me.

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