Home > php教程 > php手册 > PHP获取图片颜色值

PHP获取图片颜色值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:37:43
Original
2022 people have browsed it

   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?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template