rlemon
03-09-2006, 06:43 PM
<?php
// functions
function convertHEX($hex){
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
$rs = array('r'=>$r,'g'=>$g,'b'=>$b);
return($rs);
}
function reduceHEX($hex){
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
if($r > $g && $r > $b){
$g = $g*1.1; $b = $b*1.1;
} else if($g > $r && $g > $b){
$r = $r*1.1; $b = $b*1.1;
} else if($b > $g && $b > $r){
$g = $g*1.1; $r = $r*1.1;
}
if($r > 255){ $r = 255;}
if($g > 255){ $g = 255;}
if($b > 255){ $b = 255;}
$rs = array('r'=>$r,'g'=>$g,'b'=>$b);
return($rs);
}
/// main
$width = intval($_REQUEST['width']);
$height = intval($_REQUEST['height']);
$color = convertHEX($_REQUEST['color']);
$bgcolor = convertHEX($_REQUEST['bgcolor']);
$image = imagecreatetruecolor($width,$height);
$bg = imagecolorallocate($image, $bgcolor['r'],$bgcolor['g'],$bgcolor['b']); // image bg colour
imagefill($image, 0, 0, $bg);
$col = imagecolorallocate ( $image, $color['r'],$color['g'],$color['b']); // image foreground colour
$corColor = reduceHEX($_REQUEST['color']); // for colour edge fix
$colCor = imagecolorallocate ( $image, $corColor['r'],$corColor['g'],$corColor['b']);
imagefilledarc ( $image, $height/2, ($height/2)-1, $height+1, $height, 180, 270, $colCor, IMG_ARC_PIE); // left side arc correction
imagefilledarc ( $image, $height/2, $height/2, $height-1, $height-1, 180, 270, $col, IMG_ARC_PIE); // left side arc
imagefilledarc ( $image, $width-($height/2), ($height/2)-1, $height+1, $height, 270, 360, $colCor, IMG_ARC_PIE); // right side arc correction
imagefilledarc ( $image, $width-($height/2), $height/2, $height-1, $height-1, 270, 360, $col, IMG_ARC_PIE); // right side arc
imagefilledrectangle ( $image, 0, ($height/2)-1, $width, $height, $col ); // bottom rectangle
imagefilledrectangle ( $image, $height/2, 0, $width-($height/2)+2, ($height/2), $col ); // top rectangle
header("Content-type: image/png");
imagepng($image);
?>
there it is.
can be seen here http://rlemon.com/upgrade/
* functionality removed *notice i have added the functionality to put a small strip of colour at the top. i'm using this for a mouseover effect (maybe).
* functionality removed *
usage:
ImageTab.php?height=IMAGE_HEIGHT&width=IMAGE_WIDTH&color=COLOR_CODE_WITHOUT_#&bgcolor=BG_COLOR_CODE_WITHOUT_#
// functions
function convertHEX($hex){
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
$rs = array('r'=>$r,'g'=>$g,'b'=>$b);
return($rs);
}
function reduceHEX($hex){
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
if($r > $g && $r > $b){
$g = $g*1.1; $b = $b*1.1;
} else if($g > $r && $g > $b){
$r = $r*1.1; $b = $b*1.1;
} else if($b > $g && $b > $r){
$g = $g*1.1; $r = $r*1.1;
}
if($r > 255){ $r = 255;}
if($g > 255){ $g = 255;}
if($b > 255){ $b = 255;}
$rs = array('r'=>$r,'g'=>$g,'b'=>$b);
return($rs);
}
/// main
$width = intval($_REQUEST['width']);
$height = intval($_REQUEST['height']);
$color = convertHEX($_REQUEST['color']);
$bgcolor = convertHEX($_REQUEST['bgcolor']);
$image = imagecreatetruecolor($width,$height);
$bg = imagecolorallocate($image, $bgcolor['r'],$bgcolor['g'],$bgcolor['b']); // image bg colour
imagefill($image, 0, 0, $bg);
$col = imagecolorallocate ( $image, $color['r'],$color['g'],$color['b']); // image foreground colour
$corColor = reduceHEX($_REQUEST['color']); // for colour edge fix
$colCor = imagecolorallocate ( $image, $corColor['r'],$corColor['g'],$corColor['b']);
imagefilledarc ( $image, $height/2, ($height/2)-1, $height+1, $height, 180, 270, $colCor, IMG_ARC_PIE); // left side arc correction
imagefilledarc ( $image, $height/2, $height/2, $height-1, $height-1, 180, 270, $col, IMG_ARC_PIE); // left side arc
imagefilledarc ( $image, $width-($height/2), ($height/2)-1, $height+1, $height, 270, 360, $colCor, IMG_ARC_PIE); // right side arc correction
imagefilledarc ( $image, $width-($height/2), $height/2, $height-1, $height-1, 270, 360, $col, IMG_ARC_PIE); // right side arc
imagefilledrectangle ( $image, 0, ($height/2)-1, $width, $height, $col ); // bottom rectangle
imagefilledrectangle ( $image, $height/2, 0, $width-($height/2)+2, ($height/2), $col ); // top rectangle
header("Content-type: image/png");
imagepng($image);
?>
there it is.
can be seen here http://rlemon.com/upgrade/
* functionality removed *notice i have added the functionality to put a small strip of colour at the top. i'm using this for a mouseover effect (maybe).
* functionality removed *
usage:
ImageTab.php?height=IMAGE_HEIGHT&width=IMAGE_WIDTH&color=COLOR_CODE_WITHOUT_#&bgcolor=BG_COLOR_CODE_WITHOUT_#