darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 Try This: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> <?php // Create a new true color image $im = new imagecreatetruecolor(100, 100); // Convert to palette-based with no dithering and 255 colors imagetruecolortopalette($im, false, 255); // Set the content-type header('Content-type: image/gif'); // The text to draw $text = $_POST['name']; // Replace path by your own font path $font = 'arial.ttf'; // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagegif($im); imagedestroy($im); ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667254 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 Ignore all the Above it is not what you need This should take a gif image check to see if it is loaded and then if loaded write the text to it and output <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> <?php //load the image to be written on $im = imagecreatefromgif("image.gif"); //checking for image if($_POST['name']==""||empty($_POST['name'])){ die("Please Input a Name!"); } if(!$im) { die("Could not load image!");} else if($im) { // Set the content-type header('Content-type: image/gif'); // The text to draw $text = $_POST['name']; // Replace path by your own font path $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); //set font color // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagegif($im); //output image with text imagedestroy($im); //tidy up memory } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667310 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 ok, now I'm getting this error: Warning: imagecreatefromgif(image.gif) [function.imagecreatefromgif]: failed to open stream: No such file or directory in /var/www/vhosts/tlb.plesk.freepgs.com/httpdocs/siggyscript.php on line 23 Could not load image! It can't be because of the directory it's in. I use that area for php files all the time.(phpBB2 board) I don't understand. Sorry for so much confusion on my part. Thanks for helping. Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667346 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 replace "image.gif" with the IMAGE you want the text to write to :-X Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667347 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 I did that. Now the script runs before the user enters a name so you get the "Please Input a Name!" on the page as soon as you open it. Should the script be written as a function and then called when the user clicks the submit button? Also, if you add a name then click enter, you get the error message: The image "http://tlb.plesk.freepgs.com/siggyscript.php" cannot be displayed because it contains errors. I'm assuming that's from the <?php echo $_SERVER['PHP_SELF'];? I'm looking through my book. There's explanations of forms and handling images but not how to use them together. I need more books. Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667362 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 sorry fixed it, i forgot to make sure it was submitted first <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <?php $submit= $_POST['submit']; if(!$submit){?> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> <?php }else{ //load the image to be written on $im = imagecreatefromgif("image.gif"); //check for empty field if($_POST['name']==""||empty($_POST['name'])){ //checking for image if(!$im) { die("Could not load image!");} else if($im) { // Set the content-type header('Content-type: image/gif'); // The text to draw $text = $_POST['name']; // Replace path by your own font path $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagegif($im); imagedestroy($im);} } ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667366 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 I'm getting a syntax error in this area: if($_POST['name']==""||empty($_POST['name' //checking for image if(!$im) { die("Could not load image!");} else if($im) { // Set the content-type header('Content-type: image/gif'); Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667380 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 i know i fixed it above look again Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667383 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 hopefully this fixed the unexpected T_ELSE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <?php $submit= $_POST['submit']; if(!$submit){?> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> <?php }else{ //load the image to be written on $im = imagecreatefromgif("image.gif"); //check for empty field if($_POST['name']==""||empty($_POST['name'])){ //checking for image if(!$im) { die("Could not load image!");} // Set the content-type header('Content-type: image/gif'); // The text to draw $text = $_POST['name']; // Replace path by your own font path $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagegif($im); imagedestroy($im);} ?> </div> </body> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667414 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 Final fix: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <?php $submit= $_POST['submit']; if(!$submit){?> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> <?php }else{ //load the image to be written on $im = imagecreatefromgif("image.gif"); //check for empty field if($_POST['name']==""||empty($_POST['name'])){ die("please enter a name!");} //checking for image if(!$im) { die("Could not load image!");} // Set the content-type header('Content-type: image/gif'); // The text to draw $text = $_POST['name']; // Replace path by your own font path $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagegif($im); imagedestroy($im);} ?> </div> </body> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667433 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 Getting this error: The image "http://tlb.plesk.freepgs.com/siggyscript.php" cannot be displayed because it contains errors. Are you sure it isn't from this: <?php echo $_SERVER['PHP_SELF'];?> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667456 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 put this in your script tell me what errors pop up ok ??? <?php ini_set('error_reporting',E_ALL);?> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667461 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 No change Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667469 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 ok i figured it out it needs to be 2 seperate pages seperate the PHP from the html have the html on something called form.html or what not. than have action.php which will be the PHP code now the action on the form will be action=action.php get it ??? Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667473 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 Yep! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-667489 Share on other sites More sharing options...
dragonqueen Posted October 19, 2008 Author Share Posted October 19, 2008 Got both pages set up. I'm getting this error message when I submit the form(with Patty entered in the textbox): The image “http://tlb.plesk.freepgs.com/siggyscript.php?name=Patty&submit=Submit” cannot be displayed, because it contains errors. Here's the form page in html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Sample Siggy Script!</title> </head> <body> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="get" action="siggyscript.php"> <p> <input name="name" type="text" id="name" value="Your Name Here" size="25" maxlength="23"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> </div> </body> </html> Here's the php page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Your tag is ready!</title> </head> <body> <?php //load the image to be written on $im = imagecreatefromgif("Tag4Marcy.gif"); //checking for image if(!$im) { die("Could not load image!"); } // The text to draw $text = $_POST['name']; $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Set the content-type header('Content-type: image/gif'); imagegif($im); imagedestroy($im); ?> <?php ini_set('error_reporting',E_ALL); ?> </body> </html> I'll continue to keep looking for the problem myself. Any help is greatly appreciated. Here's the url again: http://tlb.plesk.freepgs.com/siggyscript.html Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-668918 Share on other sites More sharing options...
dragonqueen Posted October 20, 2008 Author Share Posted October 20, 2008 ok, I got the error message narrowed down to this: The image “http://tlb.plesk.freepgs.com/siggyscript.php" cannot be displayed, because it contains errors. Any suggestions ??? html page: <html> <head> <title>Sample Siggy Script!</title> </head> <body> <div align="center"> <p><img src="http://tlb.plesk.freepgs.com/Tag4Marcy.gif" width="113" height="117"></p> <form name="form1" method="post" action="/siggyscript.php"> <p> <input name="name" type="text" id="name" value="Enter Name" size="14" maxlength="10"> </p> <p> <input name="submit" type="submit" id="submit" value="Submit"> </p> </form> </div> </body> </html> php page: <html> <head> <title>Your tag is ready!</title> </head> <body> <?php // Set the content-type header("Content-type: image/gif"); //load the image to be written on $im = imagecreatefromgif("Tag4Marcy.gif"); //checking for image if(!$im) { die("Could not load image!"); } // The text to draw $text = $_POST['name']; $font = 'arial.ttf'; $black = imagecolorallocate($im, 0, 0, 0); // Add the text imagettftext($im, 20, 0, 10, 20, -$black, $font, $text); header('Content-type: image/gif'); imagegif($im); imagedestroy($im); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-669755 Share on other sites More sharing options...
darkfreaks Posted October 20, 2008 Share Posted October 20, 2008 did you try <?php ini_set('error_reporting',E_ALL); ?> to see if any warnings or notices pop up besides that one ??? Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-669759 Share on other sites More sharing options...
dragonqueen Posted October 20, 2008 Author Share Posted October 20, 2008 yes, I had that in there and it didn't do anything. I'll add it back for future tries though. edit: It's added back but still the same error. Quote Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/page/2/#findComment-669763 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.