Log in

View Full Version : PHP and form assistance needed.



redrubi
02-28-2008, 03:06 PM
Help!!

Can some one tell me how to hide the default font size in the code below. Curently a user can enter any FONT size they want but I would simply like a default font size and hide the field completely. This is a php script that lets the user preview their desired text in the selected font.

The part I need to change is in red.
Thanks in advance.

$text = stripslashes($_GET['text']);
$filename = $_GET['filename'];
$size = $_GET['size'];

if (isset($_GET['render'])) {
Header ("Content-type: image/png");
$fonturl = $fontdir.'/'.$filename;
$textdims = ImageTTFBBox($size, 0, $fonturl, $text);
$im = imagecreate ($textdims[2]-$textdims[6]+10, $textdims[3]-$textdims[7]+10);
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageTTFText ($im, $size, 0, 0, -$textdims[5], $black, $fonturl, $text);
ImagePng ($im);
ImageDestroy ($im);
die();
} else {
?><HTML>
<head>
<title>YakTagz Live Font Previewer</title>
<style type="text/css"><!--
body {font-family:georgia, verdana; scrollbar-base-color:white; scrollbar-face-color:black; scrollbar-track-color:white; scrollbar-highlight-color:black; scrollbar-shadow-color:white; scrollbar-darkshadow-color:white; scrollbar-arrow-color:white}
h1 {font-family: trebuchet ms, verdana}
a:link, a:visited {color:blue;text-decoration:underline}
a:active, a:hover {color:red;text-decoration:none}
--></style>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#00ff00" alink="#ff0000">
<h1 align="center">YakTagz Live Font Previewer</h1>

<br />
<div align="center">
<table><tr><td>
<form method="get">
<p>Select Font:
<select name="filename">
<?
foreach ($fontnames as $thisfile => $thisname) {
print '<option ';
if ($filename == $thisfile) echo 'selected="selected" ';
print 'value="' . $thisfile . '">' . $thisname . '</option>' . "\n";
}
?>
</select>
</p>
<p>

Font size: <input name="size" value="<? if (!$size) echo "52"; else echo $size; ?>" size="2" />


</p>
<p>Text to preview:<br /><textarea name="text" cols="25" rows="1"><? if
(isset($text)) echo $text; ?></textarea></p>
</td></tr></table>
<p><input type="submit" value="Preview Yaktag" /></p>
</form>
</div><? if (isset($filename) && isset($text)) { ?>

<center><p>
<img src="<?
echo $_SERVER['SCRIPT_NAME']."?render=1&filename=$filename&size=$size&text=".urlencode($text);
?>" /></p>
<? } ?>
<center>

The actual page is at www.yaktagz.com/preview.php if you need to see what I'm talking about.

Thanks in advance.

Nile
02-28-2008, 10:20 PM
$text = stripslashes($_GET['text']);
$filename = $_GET['filename'];
$text = '52';
if (isset($_GET['render'])) {
Header ("Content-type: image/png");
$fonturl = $fontdir.'/'.$filename;
$textdims = ImageTTFBBox($size, 0, $fonturl, $text);
$im = imagecreate ($textdims[2]-$textdims[6]+10, $textdims[3]-$textdims[7]+10);
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageTTFText ($im, $size, 0, 0, -$textdims[5], $black, $fonturl, $text);
ImagePng ($im);
ImageDestroy ($im);
die();
} else {
?><HTML>
<head>
<title>YakTagz Live Font Previewer</title>
<style type="text/css"><!--
body {font-family:georgia, verdana; scrollbar-base-color:white; scrollbar-face-color:black; scrollbar-track-color:white; scrollbar-highlight-color:black; scrollbar-shadow-color:white; scrollbar-darkshadow-color:white; scrollbar-arrow-color:white}
h1 {font-family: trebuchet ms, verdana}
a:link, a:visited {color:blue;text-decoration:underline}
a:active, a:hover {color:red;text-decoration:none}
--></style>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#00ff00" alink="#ff0000">
<h1 align="center">YakTagz Live Font Previewer</h1>

<br />
<div align="center">
<table><tr><td>
<form method="get">
<p>Select Font:
<select name="filename">
<?
foreach ($fontnames as $thisfile => $thisname) {
print '<option ';
if ($filename == $thisfile) echo 'selected="selected" ';
print 'value="' . $thisfile . '">' . $thisname . '</option>' . "\n";
}
?>
</select>
</p>
<p>

Font size: 52


</p>
<p>Text to preview:<br /><textarea name="text" cols="25" rows="1"><? if
(isset($text)) echo $text; ?></textarea></p>
</td></tr></table>
<p><input type="submit" value="Preview Yaktag" /></p>
</form>
</div><? if (isset($filename) && isset($text)) { ?>

<center><p>
<img src="<?
echo $_SERVER['SCRIPT_NAME']."?render=1&filename=$filename&size=$size&text=".urlencode($text);
?>" /></p>
<? } ?>
<center>

redrubi
02-28-2008, 10:45 PM
Thanks for the attempt but it doesn't appear to be working.



Edit,

spent some time working with it and added a form type="hidden".

This took care of it.

here's my working page. www.yaktagz.com/preview.php

Now if you can help me do a font color selection item, that would be great!