Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3339710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:31:26+00:00 2026-05-18T00:31:26+00:00

Question: Is it possible to get a colors luminance value in php? What I’m

  • 0

Question: Is it possible to get a colors luminance value in php?

What I’m trying to do is get the most “visually prominent” colors from an image with PHP. I’ve gone through all of Stack Overflow and I’ve not been able to find any solution.

Currently I’ve built a color search by images that loops through every pixel of an image, stores the colors, calculates color differences and brightness value then stores those in the database.

The problem: The results are mathematically correct, however they aren’t visually accurate to the image the colors were previously matched from. I assumed that some sort of luminance comparison might solve this problem.

I’ve noticed that when I order the results by ascending (lowest first), that the results are actually more accurate (although not as accurate in some cases). This means that the color occurrence values are much lower than when ordering DESC (highest first).

To calculate “brightness”, I’m using this—I don’t believe its that powerful:

function luminance($pixel){

   $pixel = sprintf('%06x',$pixel);
   $red = hexdec(substr($pixel,0,2))*0.30;
   $green = hexdec(substr($pixel,2,2))*0.59;
   $blue = hexdec(substr($pixel,4))*0.11;

   return $red+$green+$blue;
}

Here is one scenario that shows the problem:
http://twitpic.com/33e23p
http://twitpic.com/33e3x0

I’m also starting to wonder if my color distance function is not finding the most similar color:

function colorDistance(array $color1, array $color2) {
  return sqrt(pow($color1[0] - $color2[0], 2) +
    pow($color1[1] - $color2[1], 2) +
    pow($color1[2] - $color2[2], 2));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:31:27+00:00Added an answer on May 18, 2026 at 12:31 am

    Since your color space is standard RGB, the Wikipedia article Luminance (relative) says your multipliers on R, G, and B should be

    • R: 0.21
    • G: 0.72
    • B: 0.07

    instead of what you have. So

    function luminance($pixel){
    
       $pixel = sprintf('%06x',$pixel);
       $red = hexdec(substr($pixel,0,2))*0.21;
       $green = hexdec(substr($pixel,2,2))*0.72;
       $blue = hexdec(substr($pixel,4))*0.07;
    
       return $red+$green+$blue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question Is it possible to get the version of the Java Plugin being used
This is a really simple question. Is it possible for jQuery to get an
Is the above question possible? The effect I'm trying to achieve is similar to
THE QUESTION Is it possible to run one tab from a different Activity or
how is it possible to assign certain color to a value from matrix. For
Over in this question, Scott writes that it is possible to get the current
Question Is it possible to stop a Message Driven Bean (programmatically), so that it
Question: Is is possible, with regex, to match a word that contains the same
Question: Is it possible in back end code (not in the code behind but
Question: Is it possible to compile a program on linux using a .dll file?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.