Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Image with custom font
#1
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); 

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 770 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Image: How To Show A User Their IP In Your Signature. BreShiE 9 3,204 11-08-2011, 06:26 AM
Last Post: Contribution
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,261 10-10-2011, 01:00 PM
Last Post: Greyersting
  Random Image PHP Matt G 13 3,096 11-24-2010, 01:21 PM
Last Post: Sam

Forum Jump:


Users browsing this thread: 1 Guest(s)