Jump to content

Recommended Posts

Hello everybody,

 

Is there any way by which i can detect the HEX codes for similar colors if i input a color code ?

 

What i mean if if i enter the color code for an Orange, the output should be another shade of Orange.

 

This can be seen in action at http://feeds.feedburner.com/~fc/GotChance?bg=FF9900&fg=000000&anim=0

 

If you change the "bg" parameter, the background color changes to that color and a similar shade is applied to the smaller background. How do i do something like that ?

 

Also, how to i find HEX codes for complement colors ?

 

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/71390-detecting-hex-codes-for-similar-colors/
Share on other sites

I have seen color matching programs that do it based on the rgb value. The particular program that I have worked with gives you a percentage of how close that color was by checking the rgb values. The problem with hex is that it isn't easy to compare without converting to another color system. Heck, it isn't easy to know what color a hex number is just by looking at it, whereas looking at an rgb value gives you some numbers that you can at least guess with.

I belive what you are seeing is the mean hex code of color A and B to do this you need a math function doing something like

<?php
$num_1 = "a12345";
$num_2 = "abcde1";
$explode_1 = explode("",$num_1);
$explode_2 = explode("",$num_2;
$digits_1 = array();
$i = 0;
foreach($explode_1 as $value){
switch ($value){
	case "a":
	   $digits_1[$i] = 10;
	break;
	case "b":
	   $digits_1[$i] = 11;
	break;
	case "c":
	   $digits_1[$i] = 12;
	break;
	case "d":
	   $digits_1[$i] = 13;
	break;
	case "e":
	   $digits_1[$i] = 14;
	break;
	case "f":
	   $digits_1[$i] = 15;
	break;
	default:
		$digits_1[$i] = $value;
}
$i++;
}
$digits_2 = array();
$i = 0;
foreach($explode_1 as $value){
switch ($value){
	case "a":
	   $digits_2[$i] = 10;
	break;
	case "b":
	   $digits_2[$i] = 11;
	break;
	case "c":
	   $digits_2[$i] = 12;
	break;
	case "d":
	   $digits_2[$i] = 13;
	break;
	case "e":
	   $digits_2[$i] = 14;
	break;
	case "f":
	   $digits_2[$i] = 15;
	break;
	default:
		$digits_2[$i] = $value;
}
$i++;
}
$i = 0;
while($i <= 15){
$new_color = abs($digits_1[$i]-$digits_2[$i]);
$i++;
}
$new_color = implode($new_color);
echo "The Compimentary color: ".$new_color;
?>

 

 

I think that might do it, but I do not know hex color structure 100%

 

However I see a few problems, first I didn't reconvert >10 to a digit (For base 16), nor did I realize that if its negative I should be doing color inital + that or if its positvie color inital - this.  You can play around with the while function to return the color of your choice based on a basic algorthim of adjusting it based on the IVs

this will split out the r,g,b components for you

<?php
function  color_rgb($color)
{
    $result = array();
    
    $result['red'] = ($color >> 16) & 0xFF;
    $result['green'] = ($color >>  & 0xFF;
    $result['blue'] = $color & 0xFF;
    return $result;
}

$ar = color_rgb (0xFFFEFD);
echo '<pre>', print_r($ar, true), '</pre>';
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.