I want to convert hex colour code to colour name like
FF0000 -> Red
if you have any idea how it can possible?
I want to convert hex colour code to colour name like
if you have any idea how it can possible?
Using HTML and JavaScript, see the code :
<html>
<head>
<script type="text/javascript" src="http://chir.ag/projects/ntc/ntc.js"></script>
<script>
var result = {
r : function(hex)
{
var color = ntc.name(hex);
document.getElementsByName("namecolor")[0].value = color[1];
}
}
</script>
</head>
<body>
HEX CODE <input type="text" name="colorhex" value="ff0000" onKeyup="result.r(this.value)"><br>
COLOR NAME <input type="text" name="namecolor">
</body>
</html>
Source of the Javascript code project (and php inspired by) : http://chir.ag/projects/name-that-color/
Using PHP : This exemple a simple strict name => value, maybe can be completed by using the same method of javascript code (like delta).
<?php
$hexcolor = array(
'000000' => 'Black',
'000080' => 'Navy Blue',
'0000C8' => 'Dark Blue',
'0000FF' => 'Blue'); // Must be completed !
echo $hexcolor('000080'); // Return the strict color name
?>
low
in your DB You can create an table with 2 columns one for color name and hex code and the whenever then you can easily get color name by its hex value if exist. You can get an collection of color hex values with its name from here.
Well there is no predefined function in php and its not possible to logically generate color names without a database.
how ever it is difficult get color name exactly the code because combination of code is so much and the natural colors are bit low which have name. but you can get the exact color which code you have entered by this code
this is not related to this question this is an example for helping purpose :
<?php
$color = "00000";
if(isset($_REQUEST['color']))
{
$color = trim($_REQUEST['color']);
}
?>
<form method="post" action="">
<table>
<tr>
<td>Color Code : </td>
<td><input type="text" name="color" maxlength="6" value="<?php echo $color;?>"/></td>
<td><input type="submit" name="submit" value="go"/></td>
</tr>
</table>
</form>
<div style="background-color:<?php echo $color;?>; width:100px; height:50px;"></div>