Jump to content

Recommended Posts

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>

<?php

if(!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 text
for ($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 image
header("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!
Link to comment
https://forums.phpfreaks.com/topic/21118-help-please-with-creating-image-from-ttf/
Share on other sites

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.