PHP Two ways to get average color values for images:
$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);
Example 2, gets the value of the picture color.
<?php/** file: image_get_point.php* function: Get a picture specifies the color value of a point * collation: 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 >>) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $RGB = Dec2hex ($r). Dec2hex ($g). Dec2hex ($b); echo "Dec: $r-$g-$b & LT;BR/>hex:# $RGB ";? >
The above is PHP to get the image average color value of two ways to content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!