Support Forums

Full Version: PHP Image with custom font
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Intro
I have written a tutorial on, how to create Images with PHP and how to Watermark them.
So I tought to make another one and show you how to add, custom text using custom fonts.

I will use the signature image of Conspiracy, because I like it a lot.

Demo Wrote:[Image: tut.png]
Functions
In this tutorial I will use one new function
imagettftext();
array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

Start
Let us start out by defining our wished text and font.

PHP Code:
$font "BRUCM.ttf"// full path to your font file
$text "SupportForums.net"

The variable $font hodls the full path to the font file, NOTE: the format of the file must be .ttf.

Now let us load the image, for that we use the function imagecreatefromjpg();

PHP Code:
$image imagecreatefromjpg("conspiracy_sig.jpg"); 

And let us define the color for our text. imagecolorallocate();
I will use the red.

PHP Code:
$color imagecolorallocate($image25500); 

Now we have all that we need, so let's generate the new image.
First we add our text to the image file, imagettftext();.

PHP Code:
imagettftext($image200165185$color$font$text);

// define content-type header
header("Content-type: image/png");
// output image as a png image
imagepng($image);

// and free the memory 
imagedestroy($image);