Jump to content

[SOLVED] web form to jpeg (or any other image format)


yekis

Recommended Posts

  thanks for your reply...i already installed the gd library/image functions on my server..it works!!

 

but please forgive me, i'm a newbie to php..heh

 

  1) this is exactly what i want to happen in my web form

 

        Pls. see image

 

          http://www.geocities.com/yekis/sample.jpg

 

    2) nevertheless, once i preview my site on a browser,,i keep on getting ascii error messages (trash characters)

 

            Pls. see image

 

              http://www.geocities.com/yekis/error.jpg

   

 

  3) here's my full code (saves as delete.php) ...i can't find/determine the bug in my script..pls help me! tnx a lot

 

 

 

<html>

<head>

<meta name="author" content="Rexcel Cariaga">

<link href="xampp.css" rel="stylesheet" type="text/css">

<title></title>

</head>

 

<body>

 

 

<img src="background.png">

 

   

 

<form name="ff" action="delete.php" method="get">

 

 

    <table width="294" border="0">

              <tr>

                <td width="124"></td>

                <td width="160"></td>

              </tr>

              <tr>

                <td>Name Of Seller</td>

                <td><input type="text" name="text" size="25"></td>

              </tr>

              <tr>

                <td><p>Contact Number</p>

              </td>

                <td><label>

                  <input name="contact" type="text" id="contact" size="25">

                </label></td>

              </tr>

              <tr>

                <td>Product Name</td>

                <td><label>

                  <input name="product" type="text" id="product" size="25">

                </label></td>

              </tr>

              <tr>

                <td>Description</td>

                <td><label>

                  <textarea name="description" cols="19"

 

id="description"></textarea>

                </label></td>

              </tr>

              <tr>

                <td>Price</td>

                <td><label>

                <input name="price" type="text" id="price" size="25">

                </label></td>

              </tr>

              <tr>

                <td> </td>

                <td><center><input type="submit"

 

value="Submit"></center></td>

              </tr>

            </table>

</form>

<p>

   

</body>

</html>

 

 

  <?php

 

  //loads image??

 

$im    = imagecreatefrompng("background.png");

 

 

 

//defines text color

 

$textcolor = imagecolorallocate($im, 255, 255, 255);

 

// write the string at the top left ??

imagestring($im, 5, 0, 0, $_GET['text'], $textcolor);

 

 

//outputs the image

header("Content-Type: image/png");

imagepng($im);

imagedestroy($im);

 

?>

 

 

 

 

 

Link to comment
Share on other sites

sorry..i didn't get what you mean... i'm  a really a newbie to php..just copied the source code from a certain php website and modified it little by little until i got stuck..hehe

 

...what part of my code should i put the tags <code> </code> ?

Link to comment
Share on other sites

He means put your code inside code tags (while posting you will see a # icon) use that...

 

And about your code... you need to display the image when the user presses the submit button, you are now using that GD function when the page loads, I have modified your code... check this now

 

<?php
### when the user presses the submit button then use gd functions... 
if (isset($_POST['submit'])) 
{
//loads image??
$im = imagecreatefrompng("background.png");
//defines text color
$textcolor = imagecolorallocate($im, 255, 255, 255);
// write the string at the top left ??
imagestring($im, 5, 0, 0, $_POST['text'], $textcolor);
//outputs the image
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);
}
?>
<html>
<head>
<meta name="author" content="Rexcel Cariaga">
<link href="xampp.css" rel="stylesheet" type="text/css">
<title></title>
</head>
<body>
<img src="background.png">
<form name="ff" action="delete.php" method="post">
<table width="294" border="0">
<tr>
<td width="124"></td>
<td width="160"></td>
</tr>
<tr>
<td>Name Of Seller</td>
<td><input type="text" name="text" size="25"></td>
</tr>
<tr>
<td><p>Contact Number</p>
</td>
<td><label>
<input name="contact" type="text" id="contact" size="25">
</label></td>
</tr>
<tr>
<td>Product Name</td>
<td><label>
<input name="product" type="text" id="product" size="25">
</label></td>
</tr>
<tr>
<td>Description</td>
<td><label>
<textarea name="description" cols="19" id="description"></textarea>
</label></td>
</tr>
<tr>
<td>Price</td>
<td><label>
<input name="price" type="text" id="price" size="25">
</label></td>
</tr>
<tr>
<td> </td>
<td><center><input type="submit" value="Submit"></center></td>
</tr>
</table>
</form>
<p>
</body>
</html>

Link to comment
Share on other sites

This is the working one... please check, hope you get the idea...

<?php
### when the user presses the submti button then use gd functions... 
if (isset($_POST['submit'])) 
{
header("Content-type: image/png");

$name = $_POST['text']; # get value for name...
$contact = $_POST['contact']; # get value for contact...
$product = $_POST['product']; # get value for product...
$price = $_POST['price']; # get value for price...
$description = $_POST['description']; # get value for price...

$im     = imagecreatefrompng("background.png");
$white = imagecolorallocate($im, 255, 255, 255);

# this is for product 
imagestring($im, 5, 190, 20, $product, $white);
# this is for description...
imagestring($im, 5, 10, 80, $description, $white);
# this is for name
imagestring($im, 5, 300, 300, $name, $white);
# this is for contact address
imagestring($im, 5, 300, 320, $contact, $white);
# this is for price
imagestring($im, 5, 370, 80, $price, $white);

imagepng($im);
imagedestroy($im);
}
?>
<html>
<head>
<meta name="author" content="Rexcel Cariaga">
<link href="xampp.css" rel="stylesheet" type="text/css">
<title></title>
</head>
<body>

<form name="ff" action="delete.php" method="post">
<table width="294" border="0">
<tr>
<td width="124"></td>
<td width="160"></td>
</tr>
<tr>
<td>Name Of Seller</td>
<td><input type="text" name="text" size="25"></td>
</tr>
<tr>
<td><p>Contact Number</p>
</td>
<td><label>
<input name="contact" type="text" id="contact" size="25">
</label></td>
</tr>
<tr>
<td>Product Name</td>
<td><label>
<input name="product" type="text" id="product" size="25">
</label></td>
</tr>
<tr>
<td>Description</td>
<td><label>
<textarea name="description" cols="19" id="description"></textarea>
</label></td>
</tr>
<tr>
<td>Price</td>
<td><label>
<input name="price" type="text" id="price" size="25">
</label></td>
</tr>
<tr>
<td> </td>
<td><center><input type="submit" name="submit" value="submit"></center></td>
</tr>
</table>
</form>
<p>
</body>
</html>

Link to comment
Share on other sites

 

  hi..another question..same project but another problem aroused..regarding word wrapping...heh...

 

  this is my original code for the "description" field and it works...

 

 

  ORIGINAL CODE

--------------------------------------------------------------------

# this is for description...

      imagettftext($im, 18, 0, 10, 90, $white, $font, $description);

 

--------------------------------------------------------------------

 

.... nonetheless when i try to word wrap the string (see code below), i still get one line of

text..it doesn't go to the next line..pls..help..tnx

 

  REVISED CODE

--------------------------------------------------------------------

# this is for description...

 

 

//displays string and defines its position

        imagettftext($im, 18, 0, 10, 90, $white, $font, $description);

      $text = $imagettftext;

 

      //wraps string???

        $newtext = $newtext = wordwrap($text, 20, "<br />\n");

          echo $newtext;  ## is this needed?? 

---------------------------------------------------

 

hoping for your reply...tnx

 

 

 

 

 

  //displays string and defines its position

        imagettftext($im, 18, 0, 10, 90, $white, $font, $description);

      $text = $imagettftext;

 

      //wraps string???

        $newtext = $newtext = wordwrap($text, 20, "<br />\n");

          echo $newtext;  ## is this needed?? 

Link to comment
Share on other sites

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.