1

When I check the index page it does not show anything but a broken image.

These are the files I am using.

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 = 110;
$image_height = 40;

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

imagettftext($image, $fon_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);
King
  • 23
  • 8
  • As above check output - also consider using imagecreatetruecolor – Shaun Hare Jan 20 '14 at 15:05
  • 1
    execute this code without `header('Content-type: image/jpg');` and `imagejpeg($image)` lines. you should see errors, probably you cannot connect to GD library. BTW, don't forget about `imagedestroy($image);` at the end of script. And before creating a captcha check that you have $_SESSION['secure'] variable. If someone will point to this script it will send you a notice about uninitialized variable. Additionally everytime when you call ``you will always get the same ping. It's good to move rand() call into generate.php file – PolishDeveloper Jan 20 '14 at 15:06
  • After removing header('Content-type: image/jpg'); and imagejpeg($image) lines. I saw the error and solved it. thanks @PiotrMiazga – King Jan 20 '14 at 15:14

0 Answers0