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.
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.
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();
And let us define the color for our text. imagecolorallocate();
I will use the red.
Now we have all that we need, so let's generate the new image.
First we add our text to the image file, imagettftext();.
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: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($image, 255, 0, 0);
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($image, 20, 0, 165, 185, $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);
Source (Click to View)