Hello
How would I make a script where you would input some text, then that would make images from a font file ??
Thanks
Tom
Printable View
Hello
How would I make a script where you would input some text, then that would make images from a font file ??
Thanks
Tom
PHP GD :)
Couldn't be bothered to write my own code, so yeah here is the PHP.net tutorial with a change to make it save the image.
Make a file called text.php and inside it put:
Make a file called index.php and in it have a form send the data to text.php and name the form which you type the text into called "text".PHP Code:<?php
// Set the content-type
header("Content-type: image/gif");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = $_POST['text'];
// Replace path by your own font path
$font = 'font.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
$rand = rand(0, 60000);
// Using imagepng() results in clearer text compared with imagejpeg()
imagegif($im,'$rand.gif');
imagedestroy($im);
?>
Enjoy.
I know but i dunno GD xD
Look at my post, I editied it ;]
That wouldn't let me use a say... .ttf font file?
Yes it would.
Just upload the font to your site
And then just change: $font = 'font.ttf';
ahh yes didn't see that line ;)
Thanks :) Ill see if i can get something going xD
Now... How would I make it so that they could choose a fill and line colour like in Word for this ???
Text colour and stroke you mean.
I get:
www.revisionarea.info/generator is the link...Code:<br />
<b>Fatal error</b>: Call to undefined function: imagettftext() in <b>/home/revision/public_html/generator/gen.php</b> on line <b>20</b><br />
And ahh ok NVM about the stroke :) Ill try the colour bits when I get this working...
Index.php:
Gen.phpPHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
}
.style2 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;}
input { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
select { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
-->
</style>
</head>
<body>
<p><span class="style1">Text Generator using fonts!
<br>
</span><span class="style2">Coded by <strong>***********.co.uk</strong></span><span class="style2"><br>
<br>
</span></p>
<form method="post" action="gen.php">
<div align="center" style="border: dashed 1px; background-color: #F7F7F7">
<p><span class="style1">Text:</span><br>
<input type="text" name="text">
<br />
<br />
<span class="style1">Font:</span><br>
<select name="font">
<option value="habbo" selected="selected">Habbo Original Font</option>
</select>
<br />
<br />
<input name="Submit" type="submit" class="style2" value="Submit"> </p>
</form>
<div align="center">
<p><span class="style2">Provided by </span><span class="style1">TFN::<em>TeeGen</em></span><em class="style2"> - </em><span class="style2">Created by<strong> ***********.co.uk ;) </strong><strong><br />
</strong></span></p>
</div>
</body>
</html>
PHP Code:<?php
// Set the content-type
header("Content-type: image/gif");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = $_POST['text'];
// Replace path by your own font path
$font = 'habbo.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
$rand = rand(0, 60000);
// Using imagepng() results in clearer text compared with imagejpeg()
imagegif($im,'$rand.gif');
imagedestroy($im);
?>
Im only just starting to learn PHP bit by bit so I am a complete noob xD
Check my above post, Just above Dunko's :)
You need the GD libary installed.
If you are on shared hosting then I SERIOUSLY recommend you move hosts as the GD libary is standard.
Ahh ok, I didn't think Speed-networks had GD -.-
on 1and1 it just comes up with a blank page...
On Eclipse.co.uk hosting it just comes up withCode:The Image cannot be displayed because it contains errors
1and1 suck to start with, they probs aint even heard of GD.
Drop me a PM with the script and ill test it on my server (GD is fully working, check out my msn sig ^^)
1and1 do have GD, they are hosting my MSN Sig :P