Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2006, 06:43 PM   PM User | #1
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Tab Image generation (version 1)

PHP Code:
<?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($image00$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$height180270$colCorIMG_ARC_PIE); // left side arc correction

imagefilledarc $image$height/2$height/2$height-1$height-1180270$colIMG_ARC_PIE); // left side arc

imagefilledarc $image$width-($height/2), ($height/2)-1$height+1$height270360$colCorIMG_ARC_PIE); // right side arc correction

imagefilledarc $image$width-($height/2), $height/2$height-1$height-1270360$colIMG_ARC_PIE); // right side arc

imagefilledrectangle $image0, ($height/2)-1$width$height$col ); // bottom rectangle

imagefilledrectangle $image$height/20$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/

Edit: * 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).
Edit: * functionality removed *


usage:

ImageTab.php?height=IMAGE_HEIGHT&width=IMAGE_WIDTH&color=COLOR_CODE_WITHOUT_#&bgcolor=BG_COLOR_CODE_WITHOUT_#
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<

Last edited by rlemon; 03-10-2006 at 03:49 PM..
rlemon is offline   Reply With Quote
Old 03-09-2006, 06:45 PM   PM User | #2
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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.
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<

Last edited by rlemon; 03-10-2006 at 04:01 AM..
rlemon is offline   Reply With Quote
Old 03-13-2006, 03:29 AM   PM User | #3
StupidRalph
Senior Coder

 
Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
StupidRalph is on a distinguished road
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.
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

Last edited by StupidRalph; 03-13-2006 at 03:36 AM..
StupidRalph is offline   Reply With Quote
Old 03-13-2006, 04:08 AM   PM User | #4
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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('...');">
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Old 03-13-2006, 04:16 AM   PM User | #5
StupidRalph
Senior Coder

 
Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
StupidRalph is on a distinguished road
Oh okay I didn't realize you were working live on the script.
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.
StupidRalph is offline   Reply With Quote
Old 03-14-2006, 01:41 AM   PM User | #6
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
yea - sorry bout that
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Old 01-30-2007, 06:09 AM   PM User | #7
slpkwr
New to the CF scene

 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
slpkwr is an unknown quantity at this point
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.p...CODE_WITHOUT_#)
and it is not working either. Thank you!
slpkwr is offline   Reply With Quote
Old 03-23-2007, 02:01 PM   PM User | #8
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Quote:
Originally Posted by slpkwr View Post
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.p...CODE_WITHOUT_#)
and it is not working either. Thank you!

Server is down. Sorry... Code should work. what is your problem?>
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:58 AM.


Advertisement
Log in to turn off these ads.