回首页

动态按钮程序

<?php 

/>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> 动态按钮 >
> http://justice.loyola.edu/~rcapelli/dynamic_button/ >
> >
> 作者: Rob Capellini  >
> 最后更改日期: 1999年3月22日  >
> 注意:以下这段程序中有很大一部的代码是来源于其它人的程序,我
> 只不过把它们组合起来了,为此,我不能也不会为了下面的程序
> 而取得值得荣誉的感觉。我只是加入了一些功能性的东西。
>
>比如:
>
> http://www.phpbuilder.com/columns/rasmus19990124.php3
> http://webdev.berber.co.il/get_example.php3?count=402
>
> 这个程序是通过了GD Library创建了具有动态性的按钮,就像IE上的一样,
*在这个程序中,你可以改变按钮的大小、文字、字体、字体大小
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/


/> "gd.so" 是 GD library 文件,在 GNU\Linux 中必须的文件 >/
/>
提示:如果是在Windows下,该文件应该是——PHP_GD.DLL >/

 dl( "gd.so"
);

/> 我们还需要 Radloff Claus' 的colors.php 文件 >/
 require( "colors.php" );

/*设置一些初始化变量 >/
$BaseFontDir = "../ttf/" ;
$Fontname  = "TIMES" ;
$sz = 11;
$fgcolor = "white" ;
$bgcolor = "blue" ;
$xpad=9;
$ypad=9;
$text= "This text is the default text." ;

/>从 URL中得传来的参数 >/
$query_string  =  getenv( "QUERY_STRING" );

/> 以&为界限折分参数 >/
$env_array  =  split( "&" , $query_string);

/> 把参数名和值拆分出来,并把值转成  %XX 形式 >/
 while  (list($key, $val) =  each($env_array)) {
 list($name, $wert) =  split( "=" , $val);
$name  =  urldecode($name);
$wert  =  urldecode($wert);

// 写入 $cgivars 
$CGIVars[$name] = $wert;
}

/> 检查一下用户设定了那些值? >/
 if ($CGIVars[ "text" ])
$text = $CGIVars[ "text" ];

 if ($CGIVars[ "sz" ])
$sz = $CGIVars[ "sz" ];

 if ($CGIVars[ "font" ])
$Fontname  = $CGIVars[ "font" ];
$Font_File = $BaseFontDir . $Fontname . ".TTF"
;

 if ($CGIVars[ "xpad" ])
$xpad = $CGIVars[ "xpad" ];

 if ($CGIVars[ "ypad" ])
$ypad = $CGIVars[ "ypad" ];
 if ($CGIVars[ "fgcolor" ])
$fgcolor = $CGIVars[ "fgcolor" ];
$fg = GetColor($fgcolor);

 if ($CGIVars[ "bgcolor" ])
$bgcolor = $CGIVars[ "bgcolor" ];
$bg = GetColor($bgcolor);

/> 输出文件头类型 >/
 Header( "Content-type: image/gif" );

/> 得到所选字体的大小 >/
$size = imagettfbbox($sz,0, $Font_File,$text);

/> 得到文字的高和宽*/
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);

/> 初始化一幅图片 >/
$im = imagecreate($dx+$xpad,$dy+$ypad);
$background = ImageColorAllocate($im, $bg[ "red" ], $bg[ "green" ], $bg[ "blue" ]);
$foreground = ImageColorAllocate($im, $fg[ "red" ], $fg[ "green" ], $fg[ "blue" ]);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);

/> 开始创建图片 >/
 ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
 ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad, $white);
 ImageTTFText($im, $sz, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, $Font_File, $text);
 ImageTTFText($im, $sz, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $foreground, $Font_File, $text);

/> 把图片发送给客户端 >/
 ImageGif($im);

/> 创建了图片变量,当然要释放内存了 >/
 ImageDestroy($im);
?>


回首页