This article describes in detail two ways to obtain the average color value of an image in php. For more information, see.
Php can be used to obtain the average color of an image:
$i=imagecreatefromjpeg("jbxue.jpg");for($x=0;$x
>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: obtain the image color value.
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
Hex: # $ RGB ";?>
The above is the content of two methods for php to obtain the average color value of the image. For more information, see PHP Chinese network (www.php1.cn )!