<!DOCTYPE html PUBLIC "- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Selecting Contrast Text Color</title>
<style type="text/css">
body {
font: 10px verdana ;
margin: 0px 0px 0px 0px ;
}
p {
border: 1px solid #000000 ;
border-width: 0px 1px 1px 0px ;
float: left ;
line-height: 20px ;
margin: 0px 0px 0px 0px ;
text-align: center ;
width: 9% ;
}
</style>
</head>
<body>
<cfoutput>
<cfloop
index="intColor"
from="1"
to="#ArrayLen( arrColors )#"
step="1">
<cfset strHEX = arrColors[ intColor ] />
<cfset intRed = InputBaseN(
Mid( strHEX, 1, 1 ),
16
) />
<cfset intGreen = InputBaseN(
Mid( strHEX, 3, 1 ),
16
) />
<cfset intBlue = InputBaseN(
Mid( strHEX, 5, 1 ),
16
) />
<cfif (
(intGreen GT 9) OR
((intRed + intGreen + intBlue) GT 30)
)>
<cfset strColor = "000000" />
<cfelse>
<cfset strColor = "FFFFFF" />
</cfif>
<p style="background-color: ###strHEX# ;">
<span style="color: ###strColor# ;">
#strHEX#<br />
#intRed#:#intGreen#:#intBlue#
</span>
</p>
</cfloop>
</cfoutput>
</body>
</html>