我正在寻找像https://something.com/my/render_thumb.php?size=small这样的Iamge URL,因为如果它看起来是透明的,因为如果它是部分透明的,那么我会认为它是完全透明的,然后使用不同的图像在我的代码。我试图创建一个读取像这样的url的函数,但它抱怨$ url是字符串或类似的东西。关于如何快速检查图片网址的任何想法?检查一个图像的URL是否透明与PHP
// --pseudo php code (doesn't work) --
function check_transparent($url) {
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw = curl_exec($ch);
curl_close ($ch);
$img = ImageCreateFromJpeg($raw);
// We run the image pixel by pixel and as soon as we find a transparent pixel we stop and return true.
for($i = 0; $i < 10; $i++) {
for($j = 0; $j < 10; $j++) {
$rgba = imagecolorat($img, $i, $j);
if(($rgba & 0x7F000000) >> 24) {
return true;
}
}
}
// If we dont find any pixel the function will return false.
return false;
}