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); ?> Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/#findComment-753002 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." Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/#findComment-753010 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); ?> Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/#findComment-753038 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); ?> Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/#findComment-753042 Share on other sites More sharing options...
pmiller624 Posted February 3, 2009 Author Share Posted February 3, 2009 Thank You I got it working Link to comment https://forums.phpfreaks.com/topic/143532-solved-help-changing-picture-with-php/#findComment-753052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.