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
4
5
6
7
8
9
10
11
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...