How to detect the main color of an image in php_PHP tutorial

WBOY
Release: 2016-07-13 09:47:58
Original
873 people have browsed it

How to detect the main color of an image in php

This article describes the method of detecting the main color of an image in php. Share it with everyone for your reference. The specific implementation method is as follows:

 ?

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);

1

2 3

45 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);
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/1025321.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1025321.htmlTechArticleHow to detect the main color of an image in php. This article describes the method of detecting the main color of an image in php. Share it with everyone for your reference. The specific implementation method is as follows: ? 1 2 3 4 5 6 7 8 9 10...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template