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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.