php获取图片平均颜色值的二种方法 :
$i=imagecreatefromjpeg("jbxue.jpg");
for($x=0;$x<imagesx($i);$x++){
for($y=0;$y<imagesy($i);$y++){
$rgb=imagecolorat($i,$x,$y);
$r=($rgb>>16)&0xff;
$g=($rgb>>4)&0xff;
$b=$rgb&0xff;
$rTotal+=$r;
$gToal+=$g;
$bToal+=$b;
$total++;
}
}
$rAverage=round($rTotal/$total);
$gAverage=round($gTotal/$total);
$bAverage=round($bTotal/$total);例2,获取图片颜色的值。
<?php
/*
*文件:image_get_point.php
*功能:获取图片指定某点的颜色值
*整理:bbs.it-home.org
*/
function dec2hex($dec)
{
return strtoupper($dec>15?dechex($dec):('0'.dechex($dec)));
}
$im = imagecreatefrompng('http://localhost/image_arc.php');
$rgb = imagecolorat($im,20,20);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$RGB = dec2hex($r).dec2hex($g).dec2hex($b);
echo "dec:$r-$g-$b<br />hex:#$RGB";
?>
以上就是php获取图片平均颜色值的二种方法 的内容,更多相关内容请关注PHP中文网(www.php.cn)!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号