Jump to content

Recommended Posts

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>

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
}
?>

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.

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.  :D

sorry fixed it, i forgot to make sure it was submitted first :P

 

<!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>

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');

hopefully this fixed the unexpected T_ELSE  ;D

 

<!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>

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>

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 ???

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

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.