Two ways to get the average color value of an image in PHP

PHP中文网
Release: 2023-02-28 20:12:02
Original
1986 people have browsed it

Two methods for php to get the average color value of a picture:

$i=imagecreatefromjpeg("jbxue.jpg"); for($x=0;$x>16)&0xff; $g=($rgb>>4)&0xff; $b=$rgb&0xff; $rTotal+=$r; $gToal+=$g; $bToal+=$b; $total++; } } $rAverage=round($rTotal/$total); $gAverage=round($gTotal/$total); $bAverage=round($bTotal/$total);
Copy after login

Example 2, get the value of the color of the picture.

15?dechex($dec):('0'.dechex($dec))); } $im = imagecreatefrompng('http://localhost/image_arc.php'); $rgb = imagecolorat($im,20,20); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $RGB = dec2hex($r).dec2hex($g).dec2hex($b); echo "dec:$r-$g-$b
hex:#$RGB"; ?>
Copy after login

The above are the content of the two methods of obtaining the average color value of the image in PHP. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!