Home Index

Welcome, Guest
Welcome, Guest. Please login or register.
December 12, 2017, 03:10:32 am
Search:  
Advanced search
WJD Forum Index  |  Examples  |  php  |  Topic: Creating dynamic images from font files
Pages: [1] |   Go Down
Print
Author Topic: Creating dynamic images from font files  (Read 11340 times)
Shawn Sorrell
Administrator
Jr. Member
*****
Offline

Gender: Male
Posts: 64



WWW
« on: March 20, 2004, 10:19:31 am »

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:
Code:
<?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(40030);

// Sets the background of our image to white
 
 $white imagecolorallocate($im255255255);

// Sets the variables $black and $blue for later use
 
 $black imagecolorallocate($im000);
 
 $blue imagecolorallocate($im00255);

// This writes our text on the image see * for  variables breakdown
 
 imagettftext($im2001020$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:
Code:
<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.





« Last Edit: June 26, 2006, 04:39:28 pm by wildjokerdesign » Logged

Shawn Sorrell
Remember I am not an expert but a jack of all trades.  Information posted here should be used at your own risk. You are responsible for any changes you make to your account/website.
Pages: [1] |   Go Up
Print
WJD Forum Index  |  Examples  |  php  |  Topic: Creating dynamic images from font files
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC