PHP - imagettftext not working and GD installed

It's a long time when I'm still looking for an answer to this problem. All the solutions I find is to search for the font name, but I'm sure this is not my problem.

GD seems to be installed

array(11) { ["GD Version"]=> string(27) "bundled (**2.0.34 compatible**)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) } 

You can see my support for GD. My PHP version is 5.3, and I work on Linux.

I have tried several different code examples from different sites and nobody is working. ImageString works for me, but I need to get imagettftext to work.

This is the last code I tried now -

 <?php ini_set('display_errors', 1); error_reporting(E_ALL); // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 100) or die("Can't create image!"); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, 'arial.ttf', $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, 'arial.ttf', $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> 

Result: http://www.7679679.com/app/test-ansi.php

+6
source share
5 answers

The same problem with FreeType installed, the solution was

  $font = "./Arial.ttf"; // <--- put ./ in front of filename 
+18
source

Please note: you do not have a free type:

 ["FreeType Support"]=> bool(false) 

This feature requires both the GD library and the FreeType library.

You will need to install the Free Type library before you can use this feature.

try installing this package: s freetype, freetype-devel

If you compiled PHP, you can be sure to add the allowed freetype at compile time:

 --with-freetype-dir=/usr/include/freetype2/ --with-freetype 

Or, if you use something like YUM or APT-GET, it should be very easy to install these libraries and do a quick google ob search to get you started.

+7
source

Well, I also ran into a problem

 $font='arial.tff'; 

I think you should provide an absolute path to $ font , for example

 $font="c:/windows/fonts/arial.ttf"; 

I assume that you are a Windows user. and delete

 header('Content-Type:image/png'); 

to get a real mistake

+3
source

Andrew is right, php manual for imagettftext claims that FreeType should use imagettftext , imagettfbox and others. Most people in the GD devel package will automatically install FreeType:

Fedora / Redhat:

 yum install gd gd-devel php-gd 

Debian / Ubuntu:

 apt-get install php5-gd libgd2-xpm libgd2-xpm-dev 

This error was probably in your logs:

 PHP Fatal error: Call to undefined function imageTTFText() 
0
source

I solved this problem with this solution:

 $fontfile= __DIR__.'/Fontname.ttf'; 
0
source

All Articles