imagecolorclosestalpha() tìm index màu palette gần nhất với RGBA cho trước (RGB + alpha).
Cú pháp
imagecolorclosestalpha(resource $image, int $red, int $green, int $blue, int $alpha): int
Tham số
- alpha: 0 (đặc) - 127 (trong suốt).
Ví dụ
<?php
$img = imagecreatefrompng('https://example.com/logo.png');
imagetruecolortopalette($img, false, 255);
$idx = imagecolorclosestalpha($img, 180, 100, 150, 110);
$match = imagecolorsforindex($img, $idx);
echo "({$match['red']}, {$match['green']}, {$match['blue']}, {$match['alpha']})"; // (140, 130, 140, 0)
imagedestroy($img);
?>