files:
the_button.php // the_button image script
btn_standard.php // "style" file containing values for the_button
btn_blue.php // another "style" file containing values for the_button
the_button_test.html // test html file to test the_button.php
usage:
create all files in the same directory
get a TTF font in the same directory
change the TTF font names in the "style" files
study the_button_test.html
---[the_button.php]----
header("Content-type: image/png");
// allocate colors in form hex RGB
function hex_ImgColAll($im,$hex){
$a = hexdec(substr($hex,0,2));
$b = hexdec(substr($hex,2,2));
$c = hexdec(substr($hex,4,2));
return ImageColorAllocate($im, $a, $b, $c);
}
// check url commands
if ($_GET['style'] <> ''){
$sname = 'btn_'.$_GET['style'].'.php';
include($sname);
} else include('btn_standard.php');
if ($_GET['text'] <> '') $btn_text = $_GET['text']; // button text
if ($_GET['size'] <> '') $font_siz = $_GET['size']; // font size
if ($_GET['font'] <> '') $font_nam = $_GET['font']; // font path/name.ttf
if ($_GET['lm'] <> '') $l_margin = $_GET['lm']; // left margin size
if ($_GET['um'] <> '') $u_margin = $_GET['um']; // up margin size
if ($_GET['rm'] <> '') $r_margin = $_GET['rm']; // right margin size
if ($_GET['dm'] <> '') $d_margin = $_GET['dm']; // down margin size
if ($_GET['tc'] <> '') $text_col = $_GET['tc']; // text color in hex
if ($_GET['lc'] <> '') $line_col = $_GET['lc']; // outline color in hex
if ($_GET['fc'] <> '') $fill_col = $_GET['fc']; // fill color in hex
if ($_GET['bc'] <> '') $back_col = $_GET['bc']; // background color in hex
if ($_GET['luc'] <> '') $ltup_crn = $_GET['luc']; // left up corner size
if ($_GET['ruc'] <> '') $rtup_crn = $_GET['ruc']; // right up corner size
if ($_GET['rdc'] <> '') $rtdn_crn = $_GET['rdc']; // right down corner size
if ($_GET['ldc'] <> '') $ltdn_crn = $_GET['ldc']; // left down corner size
// main code
$box = imageftbbox ($font_siz, 0, $font_nam, $btn_text, 1);
$box2 = imageftbbox ($font_siz, 0, $font_nam, 'oo', 1);
$tw=$box[4]-$box[0];
$th=$box2[1]-$box2[5];
$img_width = ($tw+$l_margin+$r_margin)*2;
$img_height = ($th+$u_margin+$d_margin)*2;
$img = imagecreatetruecolor($img_width,$img_height);
$img_out = imagecreatetruecolor($img_width/2,$img_height/2);
$back_color = hex_ImgColAll($img_out,$back_col);
$text_color = hex_ImgColAll($img_out,$text_col);
$line_color = hex_ImgColAll($img_out,$line_col);
$fill_color = hex_ImgColAll($img_out,$fill_col);
imagecolortransparent($img_out,$back_color);
//sides
imagefilledrectangle($img,0,0,$img_width,$img_height,$fill_color);
imagerectangle($img,0,0,$img_width-1,$img_height-1,$line_color);
//left_up_corner
imagefilledrectangle($img,0,0,$ltup_crn*2,$ltup_crn*2,$back_color);
imagefilledarc($img,$ltup_crn*2,$ltup_crn*2,$ltup_crn*4,$ltup_crn*4,180,270,$fill_color,0);
imagearc($img,$ltup_crn*2,$ltup_crn*2,$ltup_crn*4,$ltup_crn*4,180,270,$line_color);
//right_up_corner
imagefilledrectangle($img,$img_width-$rtup_crn*2-1,0,$img_width,$rtup_crn*2,$back_color);
imagefilledarc($img,$img_width-$rtup_crn*2-1,$rtup_crn*2,$rtup_crn*4,$rtup_crn*4,270,360,$fill_color,0);
imagearc($img,$img_width-$rtup_crn*2-1,$rtup_crn*2,$rtup_crn*4,$rtup_crn*4,270,360,$line_color);
//right_down_corner
imagefilledrectangle($img,$img_width-$rtdn_crn*2,$img_height-$rtdn_crn*2-1,$img_width,$img_height,$back_color);
imagefilledarc($img,$img_width-$rtdn_crn*2-1,$img_height-$rtdn_crn*2-1,$rtdn_crn*4,$rtdn_crn*4,360,90,$fill_color,0);
imagearc($img,$img_width-$rtdn_crn*2-1,$img_height-$rtdn_crn*2-1,$rtdn_crn*4,$rtdn_crn*4,360,90,$line_color);
//left_down_corner
imagefilledrectangle($img,0,$img_height-$ltdn_crn*2-1,$ltdn_crn*2,$img_height,$back_color);
imagefilledarc($img,$ltdn_crn*2,$img_height-$ltdn_crn*2-1,$ltdn_crn*4,$ltdn_crn*4,90,180,$fill_color,0);
imagearc($img,$ltdn_crn*2,$img_height-$ltdn_crn*2-1,$ltdn_crn*4,$ltdn_crn*4,90,180,$line_color);
imagecopyresampled($img_out,$img,0,0,0,0,$img_width/2,$img_height/2,$img_width,$img_height);
$c_h = $img_height/2-$d_margin;
imagettftext($img_out, $font_siz, 0, $l_margin, $c_h, $text_color, $font_nam, $btn_text);
imagepng($img_out);
imagedestroy($img);
imagedestroy($img_out);
?>
---[btn_standard.php]---
$btn_text = 'the_button.php v1.0.0'; // button text
$font_siz = 8; // font size
$font_nam = "SF_P.TTF"; // font path/name.ttf
$l_margin = 5; // left margin size
$u_margin = 6; // up margin size
$r_margin = 6; // right margin size
$d_margin = 5; // down margin size
$text_col = '000000'; // text color in hex
$line_col = '000000'; // outline color in hex
$fill_col = 'dddddd'; // fill color in hex
$back_col = 'ffffff'; // background color in hex
$ltup_crn = 3; // left up corner size
$rtup_crn = 3; // right up corner size
$rtdn_crn = 3; // right down corner size
$ltdn_crn = 3; // left down corner size
?>
---[btn_blue.php]--------
$btn_text = 'blahblah';
$font_siz = 9;
$font_nam = "SF_P.TTF";
$l_margin = 5;
$u_margin = 6;
$r_margin = 6;
$d_margin = 5;
$text_col = 'ffffff';
$line_col = '000000';
$fill_col = '3366dd';
$back_col = 'ffffff';
$ltup_crn = 5;
$rtup_crn = 0;
$rtdn_crn = 5;
$ltdn_crn = 0;
?>
---[the_button_test.html]-----
01 -
02 -
03 -
04 -
05 -
06 -
07 -
08 -
09 -
10 -
10 -
11 -
13 -