View Full Version : form fields to gif

03-12-2010, 09:19 PM
I'm working on a personal project that came to me while needing a scanner to scan documents that i needed to email to banks or other places.

I needed to email a copy of my paystub to a loan office which isn't local, and I don't have a scanner so I ended up recreating the paystub in Word, then taking a screenshot.

What I want to make is a php generator where you would enter your info in the form and it generates a jpg of your paystub for download. It would not save any info or images on the server.

The only thing I have worked on before was a contact form, I don't know how to make it generate an image. Can someone help me with the php code to make a jpg from form field contents?

03-12-2010, 09:39 PM
It can be done easily with PHP GD, but I question the legality of it.
They want an actual paystub (or actual copy). Simply generating a fake
one using PHP would seem like an illegal thing to do. A person could make
a fake paystub with anyone's name on it. I don't think a bank would find
that acceptable.

But to answer your question, for other things, you need to start with a "blank"
JPEG image. An image of a paystub, ticket, etc. that has no words on it.
PHP would then place the words on it with any font and color you want. The
final image is ONE image, that can be JPEG, PNG, or GIF with the text on it.

Look up on Google: PHP GD text on image


03-12-2010, 09:44 PM
i want this as an offline only personal project. and, all they want is a copy of the paystub, so if i only use it to make copies of my actual paystubs to use, as long as all the info is the same it would still be legal to do.

03-12-2010, 11:46 PM
Well, to use PHP, you have to either have your own server, or run it on a webhost.
Display a blank JPEG image of a paystub, and I'll show you some PHP scripting for it.

03-14-2010, 07:47 PM
here is a template, and a blank one

03-15-2010, 12:29 AM
I was able to come up with a simple test example:

It puts in some default text just for the name and address.
Scroll down that screen for a form, to enter your own name.

You have a lot of data, so you should be populating the image
using a database or text file (not a form) ... as you have a ton of numbers.

I only did this much ... you get the idea.
You have to provide the JPEG and .ttf file in your directory.
You can use any font you choose (just provide the .ttf file).

Here is the index.php page:


$user="John Doe";
$paddress="1234 W. Elm St.";
$pstate="St. Paul, MN 55101";

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Paystub Test</title>
<br /><br />
<img src="print.php?pname=<?=$pname?>&paddress=<?=$paddress?>&pstate=<?=$pstate?>" alt="" />
<br /><br />
<form action="index.php" method="post">
Name: <input type="text" name="pname" value="John Doe"><br />
Address: <input type="text" name="paddress" value="1234 W. Elm St."><br />
State Zip: <input type="text" name="pstate" value="St. Paul, MN 55101"><br />
<input type="submit" name="submit" value="Display Graphic">

Here is the "print.php" file:

// Paystub Sample - Generator

// Get form variables
$pname = $_GET['pname'];
$paddress = $_GET['paddress'];
$pstate = $_GET['pstate'];

// Generate Image & set width
$image = imagecreatefromjpeg("paystubtemplateblank.jpg");
$imageWidth = imagesx($image);

// Generate Main Name
$color = imagecolorallocate($image, 0, 0, 0);
$font = "arial.ttf";
$fontSize = "11";

// This is the coordinates for each text string ... in this case: 80=left, 92=top
imagettftext($image, $fontSize, 0, 80, 92, $color, $font, $pname);

// Generate Name Section
$color = imagecolorallocate($image, 0, 0, 0);
$font = "arial.ttf";
$fontSize = "10";
imagettftext($image, $fontSize, 0, 50, 150, $color, $font, $pname);
imagettftext($image, $fontSize, 0, 50, 165, $color, $font, $paddress);
imagettftext($image, $fontSize, 0, 50, 180, $color, $font, $pstate);

// Output & Free Memory
header("Content-type: image/jpeg");