#native_company# #native_desc#
#native_cta#

button builder

By Scott Marlowe
on February 16, 2001

Version: 1.0

Type: Sample Code (HOWTO)

Category: Graphics

License: GNU General Public License

Description: Allows you to upload a button background, then select a font, text, size, and color to place on top. Very simple little script.

<?php
# Here we check to see if someone is uploading a new png to build a button on.
if ($userfile){
#	print $userfile_name."<BR>n";
	copy ($userfile,"button.png");
#	print $userfile;
#	exit;
}
if (!$text) $text="ABCD";
if (!$size) $size=25;
if (!$color) $color="ffffff";
if ($test_font){
	print "Now displaying font: $test_font<BR>";
	$tmp=str_replace(" ","+",$test_font);
	$tmp2=urlencode($text);
	print "<img src=button.html?font=$tmp&text=$tmp2&size=$size&color=$color>";
}
/*
print $test_font;
if (!$text) $text="Testing: Sxooter";
if (!$font) $font="acme_explosive/acme.TTF";
*/
# Here we find all the fonts installed in the font_path directory and make a list of them.
# Note that ttf fonts are represented by a directory here..

$font_path="/usr/share/fonts/ttf/";
$dp=opendir($font_path);
while (false!=($file = readdir($dp))){
	if ($file!="." && $file!=".."){
		if (is_dir($font_path.$file)){
			$font_name[]=$file;
		}
	}
}
closedir($dp);

# Next we look in each directory fir a file, each one being a font, and build a list of those fonts
# stored by font directory name.

foreach($font_name as $font){
	$dp=opendir($font_path.$font);
	while (false!=($file = readdir($dp))){
		if ($file!="." && $file!=".."){
			if (eregi("ttf$",$file)){
				$faces[$font][]=$file;
			}
		}
	}
}
if (!$test_font) $test_font=$font_name[0]."/".$faces[$font_faces[$font_name[0]]][0];
?>
<form name=form method=post>
<input type=text name=text value="<?php print $text;?>"><BR>
Pick a font:<select name=test_font onChange=document.form.submit();>
<option value=0>Please Choose</option>
<?php
foreach ($font_name as $font){
	for ($i=0;$i<count($faces[$font]);$i++){
		print "<option value="".$font."/".$faces[$font][$i].""";
		if ($test_font==$font."/".$faces[$font][$i]) print " SELECTED";
		print ">".$faces[$font][$i]."</option>n";
	}
}
?>
</select><BR>
Size:<input type=text name=size value="<?php print $size;?>"><BR>
Color (6 digit hex 000000 to ffffff or white, black, blue etc...):<input type=text name=color value="<?php print $color;?>"><BR>
Execute: <input type=submit name=action value="Show me!">
</form>
<HR>
Upload a new button background image:<BR>
<FORM ENCTYPE="multipart/form-data" METHOD=POST>
Send this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</FORM>