pmiller624 Posted February 2, 2009 Share Posted February 2, 2009 I would to add text to a picture using info from mysql. I am able to make the text over the image work but then i try to make a mysql connection it say the image has errors. Heres what I got This one works <?php Header ("Content-type: image/png"); $img_handle = imageCreateFromPNG ("http://www.icemelon.com/images/tutorials/bannerboy.png"); $color = ImageColorAllocate ($img_handle, 100, 100, 100); ImageString ($img_handle, 3, 10, 9, "Your IP: 5", $color); ImagePng ($img_handle); ImageDestroy ($img_handle); ?> This one doesn't and I don't know why <?php mysql_connect("localhost", "*****", "******") or die(mysql_error()); echo "Connected to MySQL<br />"; Header ("Content-type: image/png"); $img_handle = imageCreateFromPNG ("http://www.icemelon.com/images/tutorials/bannerboy.png"); $color = ImageColorAllocate ($img_handle, 100, 100, 100); ImageString ($img_handle, 3, 10, 9, "Your number: 5", $color); ImagePng ($img_handle); ImageDestroy ($img_handle); ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 It's because you're sending a header out after printing to the screen... try... <?php Header ("Content-type: image/png"); mysql_connect("localhost", "*****", "******") or die(mysql_error()); echo "Connected to MySQL<br />"; $img_handle = imageCreateFromPNG ("http://www.icemelon.com/images/tutorials/bannerboy.png"); $color = ImageColorAllocate ($img_handle, 100, 100, 100); ImageString ($img_handle, 3, 10, 9, "Your number: 5", $color); ImagePng ($img_handle); ImageDestroy ($img_handle); ?> Quote Link to comment Share on other sites More sharing options...
pmiller624 Posted February 2, 2009 Author Share Posted February 2, 2009 it still comes up with "The image “http://website.net/image.php” cannot be displayed, because it contains errors." Quote Link to comment Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 try it without the echo <?php Header ("Content-type: image/png"); mysql_connect("localhost", "*****", "******") or die(mysql_error()); $img_handle = imageCreateFromPNG ("http://www.icemelon.com/images/tutorials/bannerboy.png"); $color = ImageColorAllocate ($img_handle, 100, 100, 100); ImageString ($img_handle, 3, 10, 9, "Your number: 5", $color); ImagePng ($img_handle); ImageDestroy ($img_handle); ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 2, 2009 Share Posted February 2, 2009 dont echo anything bar the image, if there is an error, try to display an error image instead. Take a look at php.nets manual: php.net/imagecreatefrompng Example #1: <?php function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('bogus.image'); imagepng($img); imagedestroy($img); ?> Quote Link to comment Share on other sites More sharing options...
pmiller624 Posted February 3, 2009 Author Share Posted February 3, 2009 Thank You I got it working Quote Link to comment 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.