1337Reloaded Posted April 23, 2010 Share Posted April 23, 2010 Im still learning PHP by reading a PHP & MySQL book and its talking about generating images. So i typed the code that it gives but every time i try to open the web page it gives me this error. Warning: Cannot modify header information - headers already sent by (output started at C:\PHP Practice\xampp\htdocs\simplegraph.php:7) in C:\PHP Practice\xampp\htdocs\simplegraph.php on line 21 ‰PNG ��� IHDR���È���È���":9É��ÚIDATxœíÝYrâ0EáÕë¬l X°z•Ü°:–Ù°ú–Ö°º—Ó°F”а•Í°Æ•Ê°†–Ç°F—Ä°&”Á°æÞ°¦Û°fØ°&Õ°æÒ°LÏ°¬Ì°É°lÆ°Ìð,À°ŒæÝ°ìæÚ°Lç×°¬çÔ°äÑ°|äΰÜäË°<åÈ°œåÅ°üå°\fß°¼fÜ°gÙ°|gÖ°ÜgÓ°"dÐÖMú;ûv{¬Ûí£p|ÉÈ-˧s·k5M…³fjrÇgçôY CegMü3û�J[]½6ŸßkoüÙ×qÑÃÖôÓ±ëùæ[ÍÑÙ%ro|ÝRë"¶ìÂÒR+^Ï;m¯ùaT=šnË4¬G¿/0¯ÔJxmŽY} K³mÙ…µ7)“µ7>êRøl¢-ß»Â+«¡‘ÝSïfíí~¥‚ÝÜë;r5}%»¿ØKákã¯[¦aQÃÛò½Ryƒ×D`%j¤-`åj˜-`¥kŒ-`el€-`%·-`å«-`¥®Ÿ-`e¯“-`Q[À"©ƒ-`ÑWmm‹¾khXô£V¶€EëšØmtÝ°h»‹¶€E»]±,zWµ-`ÑAu¶€EÇUØuÖ°¨´S¶€E'*·,:W¡-`ÑéJl‹j:´,ªì½-`Q}ol‹.µgXtµM[À¢ý¶,jÓÊ°¨Y¯¶€E-ûþÛ~ƒ”š·,Ÿÿ�xwÀKPK����IEND®B`‚ <html> <head> <title>Simple Graph</title> </head> <body> <?php // Set up image $height = 200; $width = 200; $im = imagecreatetruecolor($width, $height); $white = imagecolorallocate($im, 255, 255, 255); $blue = imagecolorallocate($im, 0, 0, 64); // Draw on image imagefill($im, 0, 0, $blue); imageline($im, 0, 0, $width, $height, $white); imagestring($im, 4, 50, 150, 'Sales', $white); // Output image header('Content-type: image/png'); imagepng($im); // Clean up imagedestroy ($im); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/199445-php_gd2dll-doesnt-work/ Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 You're simply outputting the page as a png image. This means, any text that is not png data (That isn't in code) will result in an error, as your HTML code is not png data. Simply remove all output other than the PHP code, and do not echo/print anything and it should work. For your header error, It means it cannot send the header telling the browser it is a png image, because you already outtputted something (HTML). That's why you get the error and the erroneous data. Quote Link to comment https://forums.phpfreaks.com/topic/199445-php_gd2dll-doesnt-work/#findComment-1046805 Share on other sites More sharing options...
1337Reloaded Posted April 23, 2010 Author Share Posted April 23, 2010 You're simply outputting the page as a png image. This means, any text that is not png data (That isn't in code) will result in an error, as your HTML code is not png data. Simply remove all output other than the PHP code, and do not echo/print anything and it should work. For your header error, It means it cannot send the header telling the browser it is a png image, because you already outtputted something (HTML). That's why you get the error and the erroneous data. Wow thank you soo much!!! Most people in coding forums usually don't answer my questions so thanks a loT!! Quote Link to comment https://forums.phpfreaks.com/topic/199445-php_gd2dll-doesnt-work/#findComment-1046809 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.