serblowa Posted January 31, 2012 Share Posted January 31, 2012 Hello, I'm fairly new to PHP, and I'm trying to get the GD2 library working but I am having no luck. I have installed the library, and when I run phpinfo(); it shows that it is up and running, and all file types are supported. However, when I run the following code snippet nothing is displayed: <?php $im = @imagecreate (200, 100) or die ( "cannot create a new gd image."); $background_color = imagecolorallocate ($im, 240, 240, 240); $border_color = imagecolorallocate ($im, 50, 50, 50); $text_color = imagecolorallocate ($im, 233, 14, 91); imagerectangle($im,0,0,199,99,$border_color); imagestring ($im, 5, 10, 40, "a simple text string", $text_color ); header ("content-type: image/png"); imagepng ($im); ?> I have been struggling with this for a couple of weeks now with no luck. Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/256090-gd2-installed-but-wont-work/ Share on other sites More sharing options...
scootstah Posted January 31, 2012 Share Posted January 31, 2012 It works fine for me. Try taking the @ out of @imagecreate, and make sure error reporting is on. error_reporting(-1); ini_set('display_errors', 1); Quote Link to comment https://forums.phpfreaks.com/topic/256090-gd2-installed-but-wont-work/#findComment-1312852 Share on other sites More sharing options...
serblowa Posted February 2, 2012 Author Share Posted February 2, 2012 Well I enabled error logging and removed the @ sign, but still no luck. I entered some obviously wrong code and the error logger did show an error. However, I'm not seeing any errors when I execute the code segment above. I tried opening the script in several browsers, and I did find that Firefox threw the following error: Error: Image corrupt or truncated: http://192.168.0.176/simplegraph Source File: http://192.168.0.176/simplegraph Line: 0 Quote Link to comment https://forums.phpfreaks.com/topic/256090-gd2-installed-but-wont-work/#findComment-1313572 Share on other sites More sharing options...
serblowa Posted February 9, 2012 Author Share Posted February 9, 2012 So still no luck. I have tried some sample code online that appears to work. I have tried calling my php script from an html file and I still can't get any kind of image to display. So I am wondering if there is a minimum system requirement to get GD2 to work properly. I am using an old computer (Celeron 2Ghz with 256MB of RAM), and I am wondering if GD2 just needs more resources. I tried looking for some documentation on this and found nothing. Does anyone know if this could possibly be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/256090-gd2-installed-but-wont-work/#findComment-1316006 Share on other sites More sharing options...
PFMaBiSmAd Posted February 9, 2012 Share Posted February 9, 2012 Temporarily comment out the header(... ...); line of code and browse directly to the url of the .php file (i.e. don't use an <img src='' tag in a html page.) The URL you posted doesn't have any extension. Are you using some url rewriting that perhaps doesn't work? Does any .php code work on your localhost system? Quote Link to comment https://forums.phpfreaks.com/topic/256090-gd2-installed-but-wont-work/#findComment-1316008 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.