Php two ways to obtain the average color of an image

Source: Internet
Author: User
This article describes in detail two ways to obtain the average color value of an image in php. For more information, see. Php can be used to obtain the average color of an image:

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

Example 2: obtain the image color value.

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

The above is the content of two methods for php to obtain the average color value of the image. For more information, see PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.