Text is not showing on image create by gd library

432 Views Asked by At

i have developed this code for image but the problem is that my text is not appearing on this image please help ! code is running fine with no error. Displaying the white image as mentioned in this code.

<?php
//Set the Content Type
header('Content-type: image/jpg');

$w=730;
$h=450;

$image=imagecreate($w,$h);
$text='hello world';

$whitebackground=imagecolorallocate($image,255,255,255);

$blacktext=imagecolorallocate($image,0,0,0);
$font =$font_path = dirname(__FILE__) . '/themify.ttf';

imagettftext($image,40,0,50,50,$blacktext,$font,$text);
imagejpeg($image);

ini_set("log_errors", 1); ini_set("error_log", "php-error.log");
?>
1

There are 1 best solutions below

1
johirpro On

I've run the following code and it is working fine. Only change is font type, I've used the arial.ttf font. I've attached the output file.

<?php
//Set the Content Type
header('Content-type: image/jpg');

$w=730;
$h=450;

$image=imagecreate($w,$h);
$text='hello world';

$whitebackground=imagecolorallocate($image,255,255,255);

$blacktext=imagecolorallocate($image,0,0,0);
$font =$font_path = dirname(__FILE__) . '/arial.ttf';

imagettftext($image,40,0,50,50,$blacktext,$font,$text);
imagejpeg($image);
?>

enter image description here