For this example all files are located in the directory
/fonts on WH accounts the path to the font file would be
/var/www/html/fonts.
The basic code in the php file that is called looks like this:
<?php
// Tells the browser what we are sending it.
header("Content-type: image/jpeg");
// Creates our image at a size of 400 x 30
$im = imagecreate(400, 30);
// Sets the background of our image to white
$white = imagecolorallocate($im, 255, 255, 255);
// Sets the variables $black and $blue for later use
$black = imagecolorallocate($im, 0, 0, 0);
$blue = imagecolorallocate($im, 0, 0, 255);
// This writes our text on the image see * for variables breakdown
imagettftext($im, 20, 0, 10, 20, $black, "/path/file", "text");
// Outputs our image to the browser
imagejpeg($im);
// Destroys our image
imagedestroy($im);
?>
The above code is called using an image tag ans looks like this:
<img src="/pathtophpfile/thefile.php">
* (image, fontsize, fontangle, x location, y location, font color, path to font file, the text to write)
Below is the output of four files font.php, font2.php, font3.php and font4.php. Each php file has been called here by using the image tag. Each image is linked to a text file of what the actual php file looks like.
EXAMPLE ONE: Using the times.ttf file
EXAMPLE TWO: Using the gothic.ttf file
EXAMPLE THREE: Using the arial.ttf file
EXAMPLE FOUR: Using all three font files and switching between black an blue on one image.
EXAMPLE FIVE: Here we are creating our image from an existing image and overlaying text on it. We then display the image and write it to a new file. The first image is a normal image tag call to the original image. The second is a normal image tag call to the last time this page was accessed and the file that was written then. Our third image here is a call to the php file it is also linked to a text file for you to view.


