Home > php教程 > php手册 > body text

php检测图片主要颜色的方法

WBOY
Release: 2016-06-13 08:59:06
Original
847 people have browsed it

php检测图片主要颜色的方法

   本文实例讲述了php检测图片主要颜色的方法。分享给大家供大家参考。具体实现方法如下:

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

$i = imagecreatefromjpeg("image.jpg");

for ($x=0;$x

for ($y=0;$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);

  希望本文所述对大家的php程序设计有所帮助。

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template