PHP getting image color value _ PHP Tutorial

Source: Internet
Author: User
PHP obtains the image color value. PHP code for obtaining the image color value and checking the main color of the image: viewsourceprint? 0102$iimagecreatefrom((photo3.jpg); test the image and define one by yourself. pay attention to the code for obtaining the image color value in the path 03for ($ PHP and checking the main color of the image:

View sourceprint? 01

02 $ I = imagecreatefromjpeg ("photo3.jpg"); // test the image. define one by yourself. pay attention to the path.

03for ($ x = 0; $ x

04 for ($ y = 0; $ y

05 $ rgb = imagecolorat ($ I, $ x, $ y );

06 $ r = ($ rgb> 16) & 0xFF;

07 $ g = ($ rgb >>& 0xFF;

08 $ B = $ rgb & 0xFF;

09 $ rTotal + = $ r;

10 $ gTotal + = $ g;

11 $ bTotal + = $ B;

12 $ total ++;

13}

14}

15 $ rAverage = round ($ rTotal/$ total );

16 $ gAverage = round ($ gTotal/$ total );

17 $ bAverage = round ($ bTotal/$ total );

18 // example:

19 echo $ rAverage;

20?>

Lateral view sourceprint? 01 02$ I ?imagecreatefrom=(photo3.jpg); // test the image and define one by yourself. Note that the path 03for ($...

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.