PHP Test Image Main Color

Source: Internet
Author: User
How does PHP detect the main color of a picture? This article mainly introduces the method that PHP detects the main color of the picture, and involves the related operation skill of PHP for the picture. We hope to help you.

In this paper, we describe the main color of PHP detection method. Share to everyone for your reference. The implementation method is as follows:


$i = Imagecreatefromjpeg ("Image.jpg"); for ($x =0; $x <imagesx ($i); $x + +) {for  ($y =0; $y <imagesy ($i); $y + +) {    $rgb = Imagecolorat ($i, $x, $y);    $r  = ($rgb >>) & 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);

Related recommendations:

PHP Basic Tutorial 16 using the GD library for graphic drawing

PHP image operation class, support to generate thumbnails, add watermarks, upload thumbnails

Very strong PHP image processing class

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.