0

I am using a GD library to generate captcha image. But the image is not showing up. Can you please help me with it. This is a text converted to captcha image index.php

<?php
session_start();
$_SESSION['secure']=rand(1000,9999);
?>

<img src="generate.php" />

generate.php

<?php 
session_start();
header('Content-type: image/jpeg');
$text = $_SESSION['secure'];
$font_size=30;

$image_width=200;
$image_height=40;

$image = imagecreate($image_width,$image_height );
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);

?>

These above are the two files with which I am trying to generate a captcha image. But the image is not showing up. My GD library is enabled, i have had a check on it. Any help would be appreciated.

Abhay Varma
  • 67
  • 1
  • 6

1 Answers1

0

From documentation

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.

So try something like:

$font = "/path_to_folder/font.ttf";

imagettftext($image, $font_size, 0, 15, 30, $text_color, $font, $text);

This work for me.

Sinisa
  • 82
  • 1
  • 4