Jump to content

Dynamic Signatures


Recommended Posts

Hi, to make a long.. long story short.

I found this thread:

http://www.msfn.org/board/index.php?showtopic=47730

While searching about how to make my own Dynamic Signature code.

Now to the hard part, I'll try to explain it without sounding crazy.

I would like to know how make it, so that my Dynamic sig code, would be created, when someone fills out a form.

An example:

Name: [bob]

Age: [19]

Activities: [sports]

[Generate]

Okay, above this is my crude form. I would like to know how to make it so that when a person fills out the form, and hits Generate, the information from that form, will be put into the dynamic sig code, so the person can save it, etc.. etc..

I know how to make the form, I just need to know how to make the PHP/PNG codes so that when the form is filled out, everything works correctly.

I am very desperate at this point in time, to get this code to work. I have been trying at it for a good 6 months now. I am not very well knowledged in PHP, and I know PHP can get very VERY extensive, but I want to do this, and feel like I have accomplished something. Lol, can you understand that?

Well, there, I tried my best not to sound crazy.. I hope you can help me, if not, it's ok.

Link to comment
Share on other sites


I think I remember making one of these a while back... But mine actually created a new file for each newly generated image to lessen the stress on the server.

Anyways, here's my 15 minutes at it assuming the file name is sig.php:

<?php

$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$sports = $_REQUEST['sports'];

// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true ) {

Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// create image w/ dimensions
$img_width = 200;
$img_height = 100;
$image = imagecreate($img_width, $img_height);

// set bg colour
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $img_width, $img_height, $white);

// border
imagefilledrectangle($image, 0, 0, $img_width, 0, $black);
imagefilledrectangle($image, 0, $img_height-1, $img_width, $img_height-1, $black);
imagefilledrectangle($image, 0, 0, 0, $img_height, $black);
imagefilledrectangle($image, $img_width-1, 0, $img_width-1, $img_height, $black);

// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/path/to/font/file.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports);

// output and destroy
imagepng($image);
imagedestroy($image);

}

// if not, go ahead and show the form
else {

print ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<title>Dynamic Signature Generator</title>
<meta http-equiv=\"Content-type\" content=\"text/html; charset=ISO-8859-1\" />
<style type=\"text/css\">
body { font-family: tahoma, verdana, arial; }
img { verical-align: middle; border-style: none; }
</style>
</head>

<body>
<h1>Dynamic Signature Generator</h1>

<form method=\"post\" name=\"sig\" action=\"sig.php\">
<small>
Name: <input type=\"text\" name=\"name\" value=\"\" /><br />
Age: <input type=\"text\" name=\"age\" value=\"\" /><br />
Sports: <input type=\"text\" name=\"sports\" value=\"\" /><br />
<input type=\"submit\" value=\"Generate\" />
</small>
</form>

</body>

</html>");

}

?>

WARNING: this is a VERY BASIC and slightly INSECURE method of doing it (because I'm not running any checks on what the user is inputting), but it gets the job done. This code should at least give you some insight as to what to expect.

Here is the form:

post-1828-1237253963_thumb.png

And the output of the form:

post-1828-1237254045_thumb.png

Hope this helps.

Cheers,

Link to comment
Share on other sites

Okay good, because little knowledge me, already found a problem, lol =/

When I try and test it out, I typed things in, and hit generate, and it takes me to a picture of a white square with a black border, but no text =/ I even put in a new text file, and made sure the access "link" to it, was right, and still nothing..

EDIT: haha, stupid me, I spelled the folder wrong.

Okay next question,

Say I had a [select] code on the form, how would I make it so it would appear on the image? meaning how would i write the .php nvmd got that one.

What about arrays? or how to place the text where I want it? How would I incorporate that in with the code I have?

Edited by Bloodrun
Link to comment
Share on other sites

What about arrays? or how to place the text where I want it? How would I incorporate that in with the code I have?

I'm not quite sure what you want to know about arrays... But to answer your other questions...

Read up on ImageTTFText here to manipulate the text: http://ca.php.net/manual/en/function.imagettftext.php

Note that you can call ImageTTFText more than once to play in case you want to manipulate each line differently, for example:

ImageTTFTextt($image, 8, 0, 10, 17, $black, '/path/to/font/file.ttf', "Name: " . $name);
ImageTTFTextt($image, 8, 0, 20, 34, $black, '/path/to/font/file.ttf', "Age: " . $age);
ImageTTFTextt($image, 10, 0, 30, 65, $black, '/path/to/font/file.ttf', "Sports: " . $sports);

First off, this will not change the appearance of the first line. Secondly, it will shift the second line over further to the right by 10 pixels. Finally, the third line will be shifted downwards a bit more and will appear in size 10pt font instead of size 8pt.

Link to comment
Share on other sites

What about arrays? or how to place the text where I want it? How would I incorporate that in with the code I have?

I'm not quite sure what you want to know about arrays... But to answer your other questions...

Read up on ImageTTFText here to manipulate the text: http://ca.php.net/manual/en/function.imagettftext.php

Note that you can call ImageTTFText more than once to play in case you want to manipulate each line differently, for example:

ImageTTFTextt($image, 8, 0, 10, 17, $black, '/path/to/font/file.ttf', "Name: " . $name);
ImageTTFTextt($image, 8, 0, 20, 34, $black, '/path/to/font/file.ttf', "Age: " . $age);
ImageTTFTextt($image, 10, 0, 30, 65, $black, '/path/to/font/file.ttf', "Sports: " . $sports);

First off, this will not change the appearance of the first line. Secondly, it will shift the second line over further to the right by 10 pixels. Finally, the third line will be shifted downwards a bit more and will appear in size 10pt font instead of size 8pt.

Oh, okay, thank you for that, now I have been been trying to get the (select) code to work with the .php, this is what im trying to do, could you point out what im doing wrong?

$location = $_REQUEST['location'] {
if('home') {
$image = @imagecreatefrompng('images/home.png');
}
if('school') {
$image = @imagecreatefrompng('images/school.png');
}
if('work') {
$image = @imagecreatefrompng('images/work.png');
}
if('mall') {
$image = @imagecreatefrompng('images/mall.png');
}
if('library') {
$image = @imagecreatefrompng('images/library.png');
}
if('market') {
$image = @imagecreatefrompng('images/market.png');
}
}

// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true && isset($location) == true)

...skipping the stuff I haven't touched yet...

// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/fonts/VAG Round.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports . "\nLocation: " . $location);

What I want to do, is for it to get the image of the selected location..

Again, I want to thank you for helping me =D

Link to comment
Share on other sites

Your syntax is incorrect. I highly suggest you do a little background reading on basic programming, specifically PHP, before going any further.

The reason it's not working is because you're not doing any comparison on $location. Here's the complete code with a drop-down list to choose your location:

<?php

$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$sports = $_REQUEST['sports'];
$location = $_REQUEST['location'];

// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true && isset($location) == true ) {

Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// check the location
if($location == "School") {
$image = imagecreatefrompng('/full/path/to/images/school.png');
}
elseif($location == "Work") {
$image = imagecreatefrompng('/full/path/to/images/work.png');
}
elseif($location == "Mall") {
$image = imagecreatefrompng('/full/path/to/images/mall.png');
}
elseif($location == "Library") {
$image = imagecreatefrompng('/full/path/to/images/library.png');
}
elseif($location == "Market") {
$image = imagecreatefrompng('/full/path/to/images/market.png');
}
else { // we'll just set the default image to home
$image = imagecreatefrompng('/full/path/to/images/home.png');
}

// set colours
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/full/path/to/verdana.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports);

// output and destroy
imagepng($image);
imagedestroy($image);

}

// if not, go ahead and show the form
else {

print ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<title>Dynamic Signature Generator</title>
<meta http-equiv=\"Content-type\" content=\"text/html; charset=ISO-8859-1\" />
<style type=\"text/css\">
body { font-family: tahoma, verdana, arial; }
img { verical-align: middle; border-style: none; }
</style>
</head>

<body>
<h1>Dynamic Signature Generator</h1>

<form method=\"post\" name=\"sig\" action=\"sig.php\">
<small>
Name: <input type=\"text\" name=\"name\" value=\"\" /><br />
Age: <input type=\"text\" name=\"age\" value=\"\" /><br />
Sports: <input type=\"text\" name=\"sports\" value=\"\" /><br />
Location:
<select name=\"location\">
<option value=\"Home\">Home</option>
<option value=\"School\">School</option>
<option value=\"Work\">Work</option>
<option value=\"Mall\">Mall</option>
<option value=\"Library\">Library</option>
<option value=\"Market\">Market</option>
</select><br />
<input type=\"submit\" value=\"Generate\" />
</small>
</form>

</body>

</html>");

}

?>

Also, be sure to use the full path to your image and font files. It'll save you time debugging if it ever causes problems otherwise.

Link to comment
Share on other sites

Your syntax is incorrect. I highly suggest you do a little background reading on basic programming, specifically PHP, before going any further.

The reason it's not working is because you're not doing any comparison on $location. Here's the complete code with a drop-down list to choose your location:

<?php

$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$sports = $_REQUEST['sports'];
$location = $_REQUEST['location'];

// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true && isset($location) == true ) {

Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// check the location
if($location == "School") {
$image = imagecreatefrompng('/full/path/to/images/school.png');
}
elseif($location == "Work") {
$image = imagecreatefrompng('/full/path/to/images/work.png');
}
elseif($location == "Mall") {
$image = imagecreatefrompng('/full/path/to/images/mall.png');
}
elseif($location == "Library") {
$image = imagecreatefrompng('/full/path/to/images/library.png');
}
elseif($location == "Market") {
$image = imagecreatefrompng('/full/path/to/images/market.png');
}
else { // we'll just set the default image to home
$image = imagecreatefrompng('/full/path/to/images/home.png');
}

// set colours
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/full/path/to/verdana.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports);

// output and destroy
imagepng($image);
imagedestroy($image);

}

// if not, go ahead and show the form
else {

print ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<title>Dynamic Signature Generator</title>
<meta http-equiv=\"Content-type\" content=\"text/html; charset=ISO-8859-1\" />
<style type=\"text/css\">
body { font-family: tahoma, verdana, arial; }
img { verical-align: middle; border-style: none; }
</style>
</head>

<body>
<h1>Dynamic Signature Generator</h1>

<form method=\"post\" name=\"sig\" action=\"sig.php\">
<small>
Name: <input type=\"text\" name=\"name\" value=\"\" /><br />
Age: <input type=\"text\" name=\"age\" value=\"\" /><br />
Sports: <input type=\"text\" name=\"sports\" value=\"\" /><br />
Location:
<select name=\"location\">
<option value=\"Home\">Home</option>
<option value=\"School\">School</option>
<option value=\"Work\">Work</option>
<option value=\"Mall\">Mall</option>
<option value=\"Library\">Library</option>
<option value=\"Market\">Market</option>
</select><br />
<input type=\"submit\" value=\"Generate\" />
</small>
</form>

</body>

</html>");

}

?>

Also, be sure to use the full path to your image and font files. It'll save you time debugging if it ever causes problems otherwise.

Oh, I had the drop already, I just didn't add it, because I didn't think that was the problem. But thanks for the help with the syntax, it's starting to get cleaer now.

I have been using this site, to get the basics of HTML/CSS/PHP/ASP etc:

http://www.w3schools.com/php/default.asp

Though it doesn't explain the kinda things I need, either that or I'm probably not thinking in general terms with the exmaples their using. Do you have any suggestions as to where I could read up on PHP?

EDIT:

Ok, i think I messed everything up.

I put in the corrections like you wrote it, but the images that are suppose to be called are suppose to be the background of the sig. So after I put the code in, I went to test it out, I filled in the form, and pressed generate, and what came up with just the name of link (as an image) which usually means somethings wrong with the code. After trying everything O could think of, to get it to work, I ended up just removed the "if..elseif...else" code, and replacing everything back to normal. And it still just shows the link as an image =/

I keep going two steps up and 4 steps back =/

Edited by Bloodrun
Link to comment
Share on other sites

I use http://www.php.net to read up on PHP.

As for your problem, what types of images are you using (i.e., JPEG, PNG, GIF, etc.)? Did you use my exact code or only make changes to yours? Can you post all of your code if it's different than mine so I can check to see what the problem is?

They are all PNG, and here is all of my code:

<?php
$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$sports = $_REQUEST['sports'];
$location = $_REQUEST['location'];

// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true && isset($location) == true) {

Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// check the location
if($location == "school") {
$image = imagecreatefrompng('/full/path/to/images/school.png');
}
elseif($location == "work") {
$image = imagecreatefrompng('/full/path/to/images/work.png');
}
elseif($location == "mall") {
$image = imagecreatefrompng('/full/path/to/images/mall.png');
}
elseif($location == "library") {
$image = imagecreatefrompng('/full/path/to/images/library.png');
}
elseif($location == "market") {
$image = imagecreatefrompng('/full/path/to/images/market.png');
}
else { // we'll just set the default image to home
$image = imagecreatefrompng('/full/path/to/images/home.png');
}

// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/fonts/VAG Round.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports);

// output and destroy
imagepng($image);
imagedestroy($image);

}

// if not, go ahead and show the form
else {

print ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<title>Dynamic Signature Generator</title>
<meta http-equiv=\"Content-type\" content=\"text/html; charset=ISO-8859-1\" />
<style type=\"text/css\">
body { font-family: tahoma, verdana, arial; }
img { verical-align: middle; border-style: none; }
</style>


</head>

<body>
<h1>Dynamic Signature Generator</h1>

<form method=\"post\" name=\"sig\" action=\"sig.php\">
<small>
Name: <input type=\"text\" name=\"name\" value=\"\" /><br />
Age: <input type=\"text\" name=\"age\" value=\"\" /><br />
Sports: <input type=\"text\" name=\"sports\" value=\"\" /><br />
Location:
<select name=\"location\">
<option value=\"home\">Home</option>
<option value=\"school\">School</option>
<option value=\"work\">Work</option>
<option value=\"library\">Library</option>
<option value=\"mall\">Mall</option>
<option value=\"market\">Market</option>
</select><br />
<br />
<input type=\"submit\" value=\"Generate\" />
</small>
</form>

</body>

</html>");

}

?>

I want to make it, so that the location chosen, will make the image the background of the entire thing..

Edited by Bloodrun
Link to comment
Share on other sites

OK, first of all, /full/path/to should be replaced with the actual full path to the file. This also applies to your font file as I'm pretty sure you don't have a fonts directory in the root of your filesystem (most likely a subdirectory of some other directory).

For example, the full path to the font file on my server is: /home/username/website/sigs/verdana.ttf

The same thing applies to your images (e.g., /home/username/website/sigs/background.png).

Remember, this is specific to the server YOU are on, so you have to find this information (assuming you're running this script on a Linux server); the path would of course be different on a Windows server.

Link to comment
Share on other sites

OK, first of all, /full/path/to should be replaced with the actual full path to the file. This also applies to your font file as I'm pretty sure you don't have a fonts directory in the root of your filesystem (most likely a subdirectory of some other directory).

For example, the full path to the font file on my server is: /home/username/website/sigs/verdana.ttf

The same thing applies to your images (e.g., /home/username/website/sigs/background.png).

Remember, this is specific to the server YOU are on, so you have to find this information (assuming you're running this script on a Linux server); the path would of course be different on a Windows server.

oh lol.. I feel stupid now, I was thinking "/full/path/to/" was a code, I should've known..

Lol ok well, right now I am using a free server, so would I actually need the "/home/username/" part?

Okay.. yeah it's still not working =/

Edited by Bloodrun
Link to comment
Share on other sites

The easiest way to find the full path is to create a PHP file with the following in it and browsing to it:

<?php phpinfo(); ?>

Look under SCRIPT_FILENAME for the full path to your sig.php file and you'll be able to figure everything else out from there.

Link to comment
Share on other sites

The easiest way to find the full path is to create a PHP file with the following in it and browsing to it:

<?php phpinfo(); ?>

Look under SCRIPT_FILENAME for the full path to your sig.php file and you'll be able to figure everything else out from there.

Okay well i did all that, and it's still just giving me the link to the page as an image. =/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...