通过文字传递创建的图形按钮

6年以前  |  阅读数:986 次  |  编程语言:PHP 

通过文字传递创建的图形按钮,详细说明请看文内英文说明
<?php Header( "Content-type: image/gif"); // info for the browser
/* PHP3 Button generator, (c) 2000 by IzzySoft (izzysoft@buntspecht.de)

$white = "255,255,255";   
$black = "0,0,0";   
$blue = "0x2c,0c6d,0xaf";   
// =====================================   
//     =============[ build color array ]===   
// now we put the needed color into an a   
//     rray (if e.g. "$textcolor=white",   
// the array $textcolor_array represents   
//     "white")   
$textcolor_array = explode(",", $$textcolor);   
// =======================[ calculate po   
//     sition of the text on the button ]===   
do {   
$textwidth = strlen($text) * imagefontwidth($font);   
$x = ($buttonwidth - $textwidth) / 2; $x = ceil($x);   
$y = $vmidth - (imagefontheight($font) / 2);   
$font--;   
} while (($x < 0) && ($font > 0)); $font++;   
// =====================================   
//     ======[ now we create the button ]===   
if (isset($width) || isset($heigth)) {// size change expected?   
$ima = imagecreatefromgif("$button.gif");// open input gif   
$im = imagecreate($buttonwidth,$buttonheigth); // create img in desired size   
$uglybg = ImageColorAllocate($im,0xf4,0xb2,0xe5);   
ImageRectangle($im,0,0,$buttonwidth,$buttonheigth,$uglybg);   
$dummy = imagecopyresized($im,$ima,0,0,0,0,$buttonwidth,$buttonheigth,$im_info[0],$im_info[1]);   
if ($dummy == "") {   
ImageDestroy($im); // if it didn't work, create default below instead   
} else {;}   
ImageDestroy($ima);   
ImageColorTransparent($im,$uglybg);   
} else {   
$im = imagecreatefromgif("$button.gif");// open input gif   
}   
if ($im == "") { $im = imagecreate($buttonwidth,$buttonheigth); // if input gif not found,   
$rblue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);// create a default box   
ImageRectangle($im,0,0,200,100,$rblue);   
}   
$color = ImageColorAllocate($im, $textcolor_array[0], $textcolor_array[1], $textcolor_array[2]); // allocate the color   
imagestring($im, $font, $x, $y, "$text", $color); // put the text on it   
ImageGif($im);// send button to browser   
ImageDestroy($im);// free the used memory   
?>         

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8