dragonqueen Posted October 16, 2008 Share Posted October 16, 2008 I am new to php...somewhat. I know how to add scripts to the phpBB2 forums. Anyway, I have never actually wrote a script. I need a script that will take someone's name from a form and add it to an image for them to save. Here is the html page... http://flamingpixels.plesk.freepgs.com/siggyscript.php It's all html but I was planning to add the php script on the same page. I have been reading books and searching websites but can't find what I need. Could someone help or at least give me someplace to look? I've already been to http://us3.php.net/ I have found how to add text to an image but not text from a form. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/ Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 If your forms input name is called 'data' for instance, and your form uses the post method, the users input will be contained within $_POST['data']. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666708 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 ok, here's what I tried..like I said, I'm new. It didn't quite work. I got a message saying the page cannot be displayed because it has errors. Here's my code: <!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=""> <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 // 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> I don't really care about the location of the text right now. I can adjust that later. I just want to figure this out. Thanks for helping. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666718 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 google captcha tutorials it's the same principle. p.s.- I see at least one error in your script: you are trying to make a header() call after you have output. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666721 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 ok, fixed that..now onto the new errors! lol Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666723 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 what errors ??? Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666724 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 http://flamingpixels.plesk.freepgs.com/siggyscript.php I think I need to call the image to be edited. There isn't anything attributed to the $im either. If I'm not making sense it's cause I don't understand it myself. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666725 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 try something like: <?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); // Save the image imagepng($im, './paletteimage.png'); imagedestroy($im); ?> Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666727 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 That narrowed it down to 1 error: Fatal error: Class 'imagecreatetruecolor' not found in /var/www/vhosts/flamingpixels.plesk.freepgs.com/httpdocs/siggyscript.php on line 23 Also, what do I put in the form action? <form name="form1" method="post" action=""> Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666730 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 its a bug in the GD library it needs to be patched or updated on the server Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666734 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 Quote its a bug in the GD library it needs to be patchd or updated on the server ok, I'll contact my host about that. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666737 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 <form name="form1" method="post" action="<?php echo $_SERVER[php_SELF];?>"> Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666749 Share on other sites More sharing options...
Lamez Posted October 16, 2008 Share Posted October 16, 2008 @darkfreaks, could you also just use a question mark "?" ? Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666752 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 it has to be an url related action like action=file.php or action=<?php echo $PHP_SELF;?> Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666756 Share on other sites More sharing options...
Lamez Posted October 16, 2008 Share Posted October 16, 2008 well, what if you just took out the action="" all together? Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666757 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 that is pretty much telling it to do nothing $PHP_SELF will redirect it to the same page Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666761 Share on other sites More sharing options...
Lamez Posted October 16, 2008 Share Posted October 16, 2008 ah, now I understand! thank you! Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666763 Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 Leaving the action out will make the form post to itself, but it will also make your (x)html invalid. Oh, and by the way. This.... <?php echo $_SERVER[php_SELF];?> Should be.... <?php echo $_SERVER['PHP_SELF'];?> And there is no such variable as $PHP_SELF anymore. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666785 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 thanks thorpe i had no idea they removed that super global variable Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-666786 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 ok? If that's not a variable now, what do I use? Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667185 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 You would use what thorpe said: $_SESSION['PHP_SELF']. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667196 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 don't you mean $_SERVER['PHP_SELF'] ??? Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667209 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 yeah that's what I meant. Typo. Was working on some session vars in a piece of code. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667210 Share on other sites More sharing options...
dragonqueen Posted October 16, 2008 Author Share Posted October 16, 2008 I added that piece of code and it got rid of the errors but it doesn't do anything. Here's what I have: <!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); // Save the image imagepng($im, './paletteimage.png'); imagedestroy($im); ?> </div> </body> </html> It should take the name entered in the text box and add it to the image for the user to save. Ignore the name already on the image...it's just for an example. Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667217 Share on other sites More sharing options...
darkfreaks Posted October 16, 2008 Share Posted October 16, 2008 LOL that wont do anything but create an image you need to have it write the text like before give me abit ill mod it for ya Link to comment https://forums.phpfreaks.com/topic/128644-form-text-on-image/#findComment-667231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.