php里面像素怎么表示,php检索图片像素最接近的色值位置

非法不多说 直接上代码

eb9a89c0cad844dfcf1ba559613954cf.png$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));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值