PHP获取图片某一点像素
工具:使用gd库
<?php
//使用gd库,以及用png图片做示例
$imagePath = 'test.png';
$res = getimagesize($imagePath);
print_r($res);
$x = $res[0] / 2;
$y = $res[1] / 2;
//需根据图片不同类型更改读取方法
$image = imagecreatefrompng($imagePath);
$rgb = imagecolorat($image, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
echo "($r,$g,$b)";
输出结果
Array
(
[0] => 673
[1] => 673
[2] => 3
[3] => width="673" height="673"
[bits] => 8
[mime] => image/png
)
(255,255,255)