萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP獲取圖片顏色值

PHP獲取圖片顏色值

   PHP獲取圖片顏色值,檢測圖片主要顏色的代碼:

  view sourceprint?01

  02$i=imagecreatefromjpeg("photo3.jpg");//測試圖片,自己定義一個,注意路徑

  03for ($x=0;$x

  04 for ($y=0;$y

  05 $rgb = imagecolorat($i,$x,$y);

  06 $r=($rgb >>16) & 0xFF;

  07 $g=($rgb >> & 0xFF;

  08 $b=$rgb & 0xFF;

  09 $rTotal += $r;

  10 $gTotal += $g;

  11 $bTotal += $b;

  12 $total++;

  13 }

  14}

  15$rAverage = round($rTotal/$total);

  16$gAverage = round($gTotal/$total);

  17$bAverage = round($bTotal/$total);

  18//示例:

  19echo $rAverage;

  20?>

copyright © 萬盛學電腦網 all rights reserved