geytjie Posted April 19, 2010 Share Posted April 19, 2010 I need urgent help - have been out of webworld for a few years and now has to build an extensive dynamic webpage for my company. I have php5.1.45, Apache 2.2 on a windows 7 pro. Php is working fine, but when I try to use the gd library to create an image, only jibberish comes out. On the php.ini everything is enabled, but it just doesn't work. Geytjie Quote Link to comment https://forums.phpfreaks.com/topic/198993-gd-library-php5-doensnt-work-on-windows-7-pls-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2010 Share Posted April 19, 2010 You either are not successfully outputting a Content-type header or you are not using an <img src="..." alt=""> tag in your HTML. Code? Quote Link to comment https://forums.phpfreaks.com/topic/198993-gd-library-php5-doensnt-work-on-windows-7-pls-help/#findComment-1044501 Share on other sites More sharing options...
geytjie Posted April 19, 2010 Author Share Posted April 19, 2010 I have tried several different examples (to see if it was just me being stupid, which is quite possible). The last one: <body> <?php try{ // define procedural function function displayTextOnImage($text='This is a sample text string'){ if(!$text){ throw new Exception('Invalid text string'); } if(!$image=imagecreate(300,200)){ throw new Exception('Error creating blank image'); } // create background color for image $backColor=imagecolorallocate($image,0,0,255); // create text color if(!$textColor=imagecolorallocate($image,255,255,255)){ throw new Exception('Error creating text color'); } // include text string into image stream if(!imagestring($image,5,10,90,$text,$textColor)){ throw new Exception('Error creating image text'); } header("Content-type:image/png"); // display image imagepng($image); // free up memory imagedestroy($image); } // display image on the browser displayTextOnImage('This text was created with GD.'); } catch(Exception $e){ echo $e->getMessage(); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198993-gd-library-php5-doensnt-work-on-windows-7-pls-help/#findComment-1044516 Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2010 Share Posted April 19, 2010 <body> <?php try{ .... You cannot output an image directly on a HTML page. You must use a HTML <img ...> tag for each image on a HTML page. The browser then fetches the image and displays it on the page. The URL that is in the src="URL_that_results_in_an_image_being_output" attribute must be to a .php file that outputs the Content-type header followed by the image data. Quote Link to comment https://forums.phpfreaks.com/topic/198993-gd-library-php5-doensnt-work-on-windows-7-pls-help/#findComment-1044519 Share on other sites More sharing options...
geytjie Posted April 19, 2010 Author Share Posted April 19, 2010 Oh, WONDERFUL! Thank you very much for being patient. It worked. Feeling very silly indeed... Quote Link to comment https://forums.phpfreaks.com/topic/198993-gd-library-php5-doensnt-work-on-windows-7-pls-help/#findComment-1044528 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.