daydreamer Posted March 27, 2009 Share Posted March 27, 2009 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 https://forums.phpfreaks.com/topic/151387-solved-making-images-with-php-error-gd-imagettftext-captcha/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2009 Share Posted March 27, 2009 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 https://forums.phpfreaks.com/topic/151387-solved-making-images-with-php-error-gd-imagettftext-captcha/#findComment-795133 Share on other sites More sharing options...
daydreamer Posted March 27, 2009 Author Share Posted March 27, 2009 Aha, finally fixed. It was because my font was called arial.TTF. Changed to arial.ttf and works fine. thanks alot. Link to comment https://forums.phpfreaks.com/topic/151387-solved-making-images-with-php-error-gd-imagettftext-captcha/#findComment-795139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.