Jump to content

Recommended Posts

Hello i have some code which is suppose to create a simple captcha image...the code was working fine until it was moved from one location to another...now what it does is the image is created...but for some reason, it's not displaying the text.

Here is my code :

<?php
session_start();

$image = imagecreate(100, 50);

$background = imagecolorallocatealpha($image, 204, 204, 204, 127);



$text = imagecolorallocate($image, 0, 0, 0);


imagettftext($image, 20, 0, 30, 30, $text, 'Gabriola.ttf', $_SESSION['captcha']);

$lines = 20;

for($i = 0; $i <= $lines; $i++){
    $x1 = rand(1, 100);
    $y1 = rand(1, 100);
    $x2 = rand(1, 100);
    $y2 = rand(1, 100);
    
    imageline($image, $x1, $y1, $x2, $y2, $text);
}


header('content-type: image/jpeg');
imagejpeg($image);

?>

this code does create the gray box and displays the 20 lines but no text.  when i echo out the $_SESSION['captcha'] on the page it displays the number generated (generated in another file)....i've even replaced that with a string and it doesn't work...the interesting thing about it is that it works on local machine but not on a hosted page...what could possibly cause this?...all the files were changed so the .ttf file is also within the same file as this page

Link to comment
https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/
Share on other sites

i did and it doesn't do anything...it just displays the gray box and the lines O.o if i echo out the imagejpeg() then it will not show the image...i even declared the session inside this file and it still doesn't do anything O.o...it's working fine on my local machine just not on this hosted site im really lost on this one  :confused:

well the thing is the code was originally working well...it was just moved into another folder somewhere else but the directories were changed in the php files to match the new location...I have no idea why this is happening...and even on local server this code is working well...i even changed the $_SESSION='hello' and it displays hello on local server...on hosted it doesn't show any text...that's why i originally thought there was something with the imagettftext() since the rest works

hey requinix, whenever i moved the header() to the top and commented it out and put error_reporting(E_ALL) it showed the error along with the binary data...it turned out that the font file was corrupted...when it was moved it's contents were copied and pasted onto a new file but it had some characters that the browser wasn't able to read im guessing so what was copied was wrong...thankyou for your help :D

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.