VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • php获取图片的主要颜色值RGB

 
复制代码
public function dominant_color()
     {
         $image = 'D:/Python/flow/test_photos/12240303_80d87f77a3_n.jpg';
         $rTotal = $gTotal = $bTotal = $total = 0;
         $i      = imagecreatefromjpeg($image);
         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 >> 8) & 0xFF;
                 $b      = $rgb & 0xFF;
                 $rTotal += $r;
                 $gTotal += $g;
                 $bTotal += $b;
                 $total++;
             }
         }
         $rAverage = round($rTotal / $total);
         $gAverage = round($gTotal / $total);
         $bAverage = round($bTotal / $total);
         $arr = array(
             'r' => $rAverage,
             'g' => $gAverage,
             'b' => $bAverage,
         );
         p($arr);
     }
复制代码
出处:

https://www.cnblogs.com/zxf100/p/16285393.html



相关教程