Jump to content

[SOLVED] Making images with php error. 'gd', imagettftext(), captcha.


daydreamer

Recommended Posts

I have written some code to make a simple captcha, it works on my computer, which is running php 5.

 

I just uploaded to my server which is php 4.4.9, I am getting this error:

"The image 'file location\exampleimage.php' cannot be displayed because it contains errors."

 

Here is my code

<?php
session_start();
// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(270, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = $_SESSION['partans'];
// Replace path by your own font path
$font = 'arial.ttf';

$size= rand(16, 22);

// Add some shadow to the text
imagettftext($im, $size, 0, 11, 25, $grey, $font, $text);

// Add the text
imagettftext($im, $size, 0, 10, 24, $black, $font, $text);

$rotate= rand(-1, 1);
$im = imagerotate($im, $rotate, $white); //rotate

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

 

Here is my server phpinfo which relates to the functions used:

gd
GD Support 	enabled
GD Version 	bundled (2.0.28 compatible)
FreeType Support 	enabled
FreeType Linkage 	with freetype
GIF Read Support 	enabled
GIF Create Support 	enabled
JPG Support 	enabled
PNG Support 	enabled
WBMP Support 	enabled
XBM Support 	enabled 

 

The font file arial.ttf is also in the correct folder.

 

Any ideas on whats wrong? Thanks.

Your file is either generating an php error or it has some characters before the opening <?php tag or after the closing ?> tag or the file was saved in UTF-8 format and the BOM (Byte Order Mark) characters at the start of the file are being output.

 

Comment out the header() statement so that you can see exactly what is being output by the file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.