How does PHP detect the main color of a picture? This article mainly introduces the method that PHP detects the main color of the picture, and involves the related operation skill of PHP for the picture. We hope to help you.
In this paper, we describe the main color of PHP detection method. Share to everyone for your reference. The 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 >>) & 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 16 using the GD library for graphic drawing
PHP image operation class, support to generate thumbnails, add watermarks, upload thumbnails
Very strong PHP image processing class