PHP Image with custom font - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: PHP Image with custom font (/showthread.php?tid=2784) |
PHP Image with custom font - Gaijin - 11-10-2009 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: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 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); Source (Click to View) |