...

View Full Version : Tab Image generation (version 1)



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_#

rlemon
03-09-2006, 06:45 PM
Note,
the corner correction is just a lighter version of the fill colour layered in behind the regular colour with 1.1x larger max width and height.

Also note, i have removed the top line - it was ugly.

StupidRalph
03-13-2006, 03:29 AM
Its printing out the new line feed on your demo page. I didn't see any \n in the code above so maybe somewhere else in your code its not encapsulated by double quotes.
Also, check your javascript code. It is throwing out 2 errors so the mouseover & mouseout effects do not work. I think its in the link .js not sure tho.

Other than that--pretty cool.

rlemon
03-13-2006, 04:08 AM
yea i've been playing around, if you can't tell by the url it's my upgrade page - so expect it to be changing. however the tabs are the ones generated by the code above.

the code above simply creates the image, and is called as an image would be
i.e. <img src="....">
or
<div style="background-image: url('...');">

StupidRalph
03-13-2006, 04:16 AM
Oh okay I didn't realize you were working live on the script.

rlemon
03-14-2006, 01:41 AM
yea - sorry bout that

slpkwr
01-30-2007, 06:09 AM
Hi, I tested the code in my linux server but it's not working. I also tested the code on the link you gave (http://rlemon.com/upgrade/ImageTab.php?height=IMAGE_HEIGHT&width=IMAGE_WIDTH&color=COLOR_CODE_WITHOUT_#&bgcolor=BG_COLOR_CODE_WITHOUT_#)
and it is not working either. Thank you!

rlemon
03-23-2007, 02:01 PM
Hi, I tested the code in my linux server but it's not working. I also tested the code on the link you gave (http://rlemon.com/upgrade/ImageTab.php?height=IMAGE_HEIGHT&width=IMAGE_WIDTH&color=COLOR_CODE_WITHOUT_#&bgcolor=BG_COLOR_CODE_WITHOUT_#)
and it is not working either. Thank you!


Server is down. Sorry... Code should work. what is your problem?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum