Reputation: 165
I want to write a text(say "my text" ) on an image using PHP5.
I am using this
$src = imagecreatefromjpeg($path);
$temp = imagecreatetruecolor($newwidth, $newheight);
$black = imagecolorallocatealpha($temp,0,0,16,75);
$start_x = 10;
$start_y = 20;
putenv('GDFONTPATH=' . realpath('.'));
$font = "LongCoolWoman";
$black = ImageColorAllocate($src, 255, 255, 255);
imagecopyresampled($temp, $src, 0,0,0,0, $newwidth, $newheight, $width, $height);
Imagettftext($src, 12, 0, $start_x, $start_y, $black, $font , "my text");
imagejpeg($temp, $path,100);
imagedestroy($temp);
i am having this error
error `imagettftext(): Could not find/open font in ...`
font file (LongCoolWoman ) and my php file are in the same folder.
Upvotes: 1
Views: 71
Reputation: 453
If the value in $font does not end with '.ttf' PHP will automatically append .ttf and search for the font in the servers font librarys. You should set the $font as follows.
$font = './LongCoolWoman.ttf'
This way the font file should be found in your current folder alongside your script.
Upvotes: 2