pwntastic Posted April 29, 2012 Share Posted April 29, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/ Share on other sites More sharing options...
requinix Posted April 29, 2012 Share Posted April 29, 2012 Comment out the header() and look for error messages. Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341490 Share on other sites More sharing options...
pwntastic Posted April 30, 2012 Author Share Posted April 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341615 Share on other sites More sharing options...
requinix Posted April 30, 2012 Share Posted April 30, 2012 Without the header() you should only be seeing the raw binary data. You should not be seeing any image at all. Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341621 Share on other sites More sharing options...
pwntastic Posted April 30, 2012 Author Share Posted April 30, 2012 yea but for some reason here it doesnt ...it still displays gray box and lines O.o even if i enter the direct url to this file...when i delete imagejpeg() then it doesn't show the image Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341630 Share on other sites More sharing options...
requinix Posted April 30, 2012 Share Posted April 30, 2012 Okay, the alternative: Save the image somewhere and open it with Notepad (or some other text editor). Do you see any error messages? Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341632 Share on other sites More sharing options...
pwntastic Posted April 30, 2012 Author Share Posted April 30, 2012 i saved the image without the header() and when i open it with notepad it just displays the binary data...infact it saved the image just how it's displayed on the page...it only allowed me to save it as .png or .bmp Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341635 Share on other sites More sharing options...
requinix Posted April 30, 2012 Share Posted April 30, 2012 [edit] Nevermind that. Only thing I can think of is TTF support on the server. phpinfo() should include a section on GD: what does it say? Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341639 Share on other sites More sharing options...
pwntastic Posted April 30, 2012 Author Share Posted April 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341640 Share on other sites More sharing options...
pwntastic Posted April 30, 2012 Author Share Posted April 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261787-help-with-imagettftext-function/#findComment-1341736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.