How to detect the main color of an image in php? This article mainly introduces the method of detecting the main color of the picture in PHP, and involves PHP's related operation skills for pictures. I hope to be helpful.
The example in this article describes the method of detecting the main color of the image in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
$i = imagecreatefromjpeg("image.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 >> & 0xFF; $b = $rgb & 0xFF; $rTotal += $r; $gTotal += $g; $bTotal += $b; $total++; } } $rAverage = round($rTotal/$total); $gAverage = round($gTotal/$total); $bAverage = round($bTotal/$total);
Related recommendations:
PHP Basic Tutorial Sixteenth Use of GD Library for graphics drawing
Strong PHP image processing class
The above is the detailed content of PHP detects the main color of the picture. For more information, please follow other related articles on the PHP Chinese website!