php接收页颜色,php – 获取图像颜色

查看

GD functions.

1px方法的一个例子(现在包括测试页):

$filename = $_GET['filename'];

$image = imagecreatefromjpeg($filename);

$width = imagesx($image);

$height = imagesy($image);

$pixel = imagecreatetruecolor(1, 1);

imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);

$rgb = imagecolorat($pixel, 0, 0);

$color = imagecolorsforindex($pixel, $rgb);

?>

Test Image Average Color<?php echo $color['green'] ?>, <?php echo $color['blue'] ?>)'>

<?php%20echo%20%24filename%20?>

下面是一些用于查找平均边框颜色的示例代码,类似于第一个链接.为了您的使用,这可能会更好(我知道这段代码效率低下,但希望很容易遵循):

$filename = $_GET['filename'];

$image = imagecreatefromjpeg($filename);

$width = imagesx($image);

$height = imagesy($image);

for($y = 0; $y < $height; $y++){

$rgb = imagecolorat($image, 0, $y);

$color = imagecolorsforindex($image, $rgb);

$red += $color['red'];

$green += $color['green'];

$blue += $color['blue'];

$rgb = imagecolorat($image, $width -1, $y);

$color = imagecolorsforindex($image, $rgb);

$red += $color['red'];

$green += $color['green'];

$blue += $color['blue'];

}

for($x = 0; $x < $height; $x++){

$rgb = imagecolorat($image, $x, 0);

$color = imagecolorsforindex($image, $rgb);

$red += $color['red'];

$green += $color['green'];

$blue += $color['blue'];

$rgb = imagecolorat($image, $x, $height -1);

$color = imagecolorsforindex($image, $rgb);

$red += $color['red'];

$green += $color['green'];

$blue += $color['blue'];

}

$borderSize = ($height=$width)*2;

$color['red'] = intval($red/$borderSize);

$color['green'] = intval($green/$borderSize);

$color['blue'] = intval($blue/$borderSize);

?>

更新:我把一些more refined code on github.这包括平均边框,平均整个图像.应该注意的是,调整到1px的资源比扫描每个像素要好得多(虽然我没有运行任何实时测试),但代码确实显示了三种不同的方法.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值