Jump to content

form text on image


dragonqueen

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.