A LUT for that is something I put together for the GIMP, once. Here's the table converted to PHP, with a function to use it. Defined over the range 1000K - 10000K.
function blackbody_colour($temperature)
{
// RGB LUT; blackbody spectrum linearly interpolated over 19 segments.
static $spectrum = array(array(255, 1, 0),
array(255, 32, 0),
array(255, 59, 2),
array(255, 88, 17),
array(255, 115, 38),
array(255, 139, 64),
array(255, 161, 94),
array(255, 181, 125),
array(255, 198, 158),
array(255, 213, 190),
array(255, 226, 221),
array(255, 238, 251),
array(231, 226, 255),
array(210, 213, 255),
array(194, 204, 255),
array(181, 195, 255),
array(170, 188, 255),
array(161, 182, 255),
array(153, 176, 255));
// clamp and normalise $temperature from Kelvin to [0,1]
$temperature = min(10000, max(1000, $temperature));
$temperature = ($temperature - 1000) / (10000 - 1000);
$point = $temperature * 18;
$lower = (int)floor($point);
$upper = (int)ceil($point);
if($lower == $upper)
{
return $spectrum[$lower];
}
else
{
$point = $point - $lower;
list($lr, $lg, $lb) = $spectrum[$lower];
list($ur, $ug, $ub) = $spectrum[$upper];
$r = intval(($ur - $lr) * $point + $lr);
$g = intval(($ug - $lg) * $point + $lg);
$b = intval(($ub - $lb) * $point + $lb);
return array($r, $g, $b);
}
}