非法不多说 直接上代码
$img = 'http://photocdn.sohu.com/20121208/Img359836294.jpg';
// 像素级别
$xs = 3;
// 是否取反
$f = true;
$im = imagecreatefromjpeg($img); //图片路径
ob_start ();
imagejpeg($im);
$image_data = ob_get_contents ();
ob_end_clean ();
$base64Img = base64_encode($image_data);
echo '';
//获取当前待修改图片像素(内置函数)
$x = imagesx($im);
$y = imagesy($im);
print_r('
');
print_r('X像素'.$x);
print_r(' Y像素'.$y);
print_r('
');
$newx = $x/$xs;
$newy = $y/$xs;
//新建一个真彩色图像(内置函数)
$i = imagecreatetruecolor($newx, $newy);
//重采样拷贝部分图像并调整大小(内置函数)
imagecopyresampled($i, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
$bk = -999;
$bx = 0;
$by = 0;
for ($y = 0; $y < imagesy($i); $y++) {
for ($x = 0; $x < imagesx($i); $x++) {
$rgb = imagecolorat($i, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$ba = $r + $g + $b;
if($f)$ba = ~$ba;
// 计算差值
if ($bk < $ba){
$bk = $ba;
$bx = $x;
$by = $y;
}
}
}
$red=imagecolorallocate($im,255,0,0);
imageellipse($im,($bx*$xs),($by*$xs),20,20,$red);
ob_start ();
imagejpeg($im);
$image_data = ob_get_contents ();
ob_end_clean ();
$base64Img = base64_encode($image_data);
echo '';
echo '
';
print_r('像素位置'.($bx*$xs).'>>'.($by*$xs));