_SAi_ Posted September 18, 2006 Share Posted September 18, 2006 Hello,I could use some help to get something working. I am trying to create an image using truetype fonts given a user's input for a phrase and a font selection.Here is what I have so far for the input form:[code]<html><head><title>FONT PREVIEW</title><style type="text/css">p {font-family:"Century Gothic", "Sans Serif"; font-size:12pt; color:black;}</style></head><body><br><br><br><p>Enter some text and Select a Font then press PREVIEW to see it:</p><form method="get" action="index.php"><input type="text" name="text_input">Font:<select name="font_input"><option value="ttf/arial.ttf">Arial</option><option value="ttf/chick.ttf">Chick</option></select>Preview Size:<select name="size_input"><option value = "small">Small</option><option value = "medium">Medium</option><option value = "large">Large</option></select><input type="submit" value="PREVIEW"></form><?phpif(!empty($_GET['font_input'])) { // make sure to validate the GET variable // before calling it into your script $img = 'section_head2.php?font_input='.$_GET['font_input'];} else { $img = 'section_head2.php';}echo "<img src=\"$img\" />";?></body></html>[/code]And here is the code I have to create it as of now:[code]<?php // if no text is provided, we will use some default text if (!isset($_GET["text_input"])) $text = "Please Enter Some Text!!"; else $text = $_GET["text_input"]; // set this to the location of the TrueType font file that you want to use if (!isset($_GET["font_input"])) $font = "ttf/arial.ttf"; else $font = $_GET["font_input"];// angle of the font in degrees$font_angle = 0;// the weight of the font stroke$stroke = 0;// the size of the font$get_font_size = $_GET["size_input"];if ($get_font_size == "large"){$font_size = 100;$startx = 10;$starty = 110;$im = imagecreate(750,125);}if ($get_font_size == "medium"){$font_size = 70;$startx = 10;$starty = 80;$im = imagecreate(750,95);}if ($get_font_size == "small"){$font_size = 40;$startx = 10;$starty = 45;$im = imagecreate(750,50);}$TextColour = imagecolorallocate($im, 150, 0, 0);$BackgroundColour = imagecolorallocate($im, 255, 255, 255);$OutlineColour = imagecolorallocate($im, 255, 255, 255); imagefilltoborder($im, 0, 0, $BackgroundColour, $BackgroundColour); // now draw out the outline (stroke) on the textfor ($ox = -$stroke; $ox <= $stroke; $ox++) { for ($oy = -$stroke; $oy <= $stroke; $oy++) { imagettftext($im, $font_size, $font_angle, $startx+$ox, $starty+$oy, $OutlineColour, $font, $text); }} imagettftext($im, $font_size, $font_angle, $startx, $starty, $TextColour, $font, $text); // set the correct HTTP header for a PNG imageheader("Content-type: image/png"); imagepng($im); // remember to free up the memory used on the server to create the image!imagedestroy($im); ?>[/code]I was able to get this working (with help) with just an input of the phrase, but now that I am trying to have a font pulldown too I cannot for the life of me get it to work.And help will be greatly appreciated!!Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/ Share on other sites More sharing options...
_SAi_ Posted September 20, 2006 Author Share Posted September 20, 2006 Wow! I've stumped em!!Is there any other info I can add to make this solveable? Quote Link to comment https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/#findComment-95709 Share on other sites More sharing options...
ober Posted September 21, 2006 Share Posted September 21, 2006 What exactly isn't working. The code looks good to me. Quote Link to comment https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/#findComment-95803 Share on other sites More sharing options...
_SAi_ Posted September 21, 2006 Author Share Posted September 21, 2006 Well, the image doesn't appear. And I'm not sure how to make a default image if not text or font is selected. If you notice in the form code there is just a default font right now at the bottom. And that doesn't even work. Quote Link to comment https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/#findComment-95843 Share on other sites More sharing options...
_SAi_ Posted September 25, 2006 Author Share Posted September 25, 2006 Ok,Let's start with this... What is the proper syntax for my form's image if I have a user input a font AND a phrase?I currently have this... but I don't know how to add in for the font (only the phrase - if that's even correct).[code]if(!empty($_GET['text_input']) && !empty($_GET['font_input'])) { // make sure to validate the GET variable // before calling it into your script $img = 'section_head2.php?text_input='.$_GET['text_input']'&font_input='.$_GET['font_input']'';} else { $img = 'section_head2.php';}echo "<img src=\"$img\" />";[/code]...I get an error on the &font= portion of the $img declaration:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/html/FontPreviews/001b/index.php on line 41 Quote Link to comment https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/#findComment-97933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.