Reputation: 10105
Problem
I get a run time error which says - Invalid font filename. I am using XAMPP in Window 8.1
It seems like I need to map any path of fonts folder present in the C:\XAMPP or please suggest.
$jpg_image = imagecreatefromjpeg('sunset.jpg');
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$font_path = 'font.TTF';
$text = "This is a sunset!";
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);
Upvotes: 0
Views: 1183
Reputation: 19780
You have to define the path using putenv
:
putenv('GDFONTPATH=' . realpath('.'));
$font_path = 'font'; // no .ttf
Have a look to http://php.net/imagettftext .
Upvotes: 2
Reputation: 5708
When you are setting fonts for the imagettftext()
you need to start the font name with a /
otherwise .TTF
will be added automatically.
Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.
resource: php.net/imagettftext.
So your font declaration should look like this:
// this is if your font is in the default GD directory
$font_path = 'font';
// default directory is set by
putenv('GDFONTPATH=' . realpath('.'));
or you could specify the whole path to the font:
// font is in some other directory
$font_path = '/path/to/font.ttf';
Upvotes: 1