<?php
    $im 
imagecreatetruecolor(400200);
    if (!
$im) {
        echo 
"Unable to create image, GD error";
    } else {
        
header("Content-type: image/png");
        if (isset(
$_GET['colour']) && (preg_match("/^([#]?)([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/"$_GET['colour']) > 0)) {
            
$colour $_GET['colour'];
            if (
$colour{0} == "#") {
                
$colour substr($colour1);
            }
            if (
strlen($colour) == 3) {
                
$colour $colour{0} . $colour{0} . $colour{1} . $colour{1} . $colour{2} . $colour{2};
            }
        } else {
            
$colour"ffffff";
        }
        
$red hexdec(substr($colour02));
        
$green hexdec(substr($colour22));
        
$blue hexdec(substr($colour42));
        
$bg imagecolorallocate($im000);
        
$fc imagecolorallocate($im$red$green$blue);
        
imagefilledrectangle($im00400200$bg);
        
imagefilledrectangle($im11398198$fc);

        
imagepng($im);
    }
?>