我正在尋找像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;
}