Want your very own Userbar Creator? Here we will show you step-by-step how to create your very own for your website!
You will need access to the files on a server that is running PHP.
Step One : The Form
The first step to making a Userbar Creator is for you to create a page with a form for users to use. Call the page whatever you like and use the code below:
Step Two: The Code
The second step requires you to copy/paste the code below and name/save that page as make_it.php.
<?php
/**************************/
/* Userbar Creator Script */
/* copyright 2010 by makeauserbar.com */
/* please do not remove copyright */
/* released under the GNU Affero General Public License */
/* More Info: http://www.fsf.org/licensing/licenses/agpl-3.0.html */
/**************************/
// Enter your site URL, such as http://www.makeauserbar.com
$home = "_____________";
// Each of the variables below come from the form the user submits
// Remove or comment out what is not used
$img_url = htmlspecialchars($_POST['image']);
$color = htmlspecialchars($_POST['color']);
$text = htmlspecialchars(stripslashes(trim($_POST['text'])));
$size = htmlspecialchars($_POST['size']);
$margin = htmlspecialchars($_POST['margin']);
$font = htmlspecialchars($_POST['font']);
// If there is a valid image URL address then let's go
if (isset($img_url)){
$im = @imagecreatefrompng('images/'.$img_url);
}else{
header('Location: $home');
exit;
}
// if nothing else, the default color is black
$color=imagecolorallocate($im, 0, 0, 0);
}
// This is the text, if they submitted something use that
if ((isset($text)) && (!empty($text))){
$text = $text;
}else{
// else use the IP address of the user
$text = "My IP: ". $_SERVER['REMOTE_ADDR'];
}
// This is the margin from the left, if they submitted something use that
if ((isset($margin)) && (!empty($margin))){
$margin = $margin;
}else{
// else use 20 from the left
$margin = '20';
}
// This is the font size, if they submitted something use that
if ((isset($size)) && (!empty($size))){
$size = $size;
}else{
// else font size is 11 pixels
$size = '11';
}
// fonts are stored in a folder named "fonts"
// This is the font family, if they submitted something use that
if ((isset($font)) && (!empty($font))){
$font = 'fonts/'.$font;
}else{
// else default font is visitor.ttf
$font ='fonts/visitor.ttf';
}
// this is the magic line, here we write text to the image using TrueType fonts
// line below explained: (image we are creating, font size, angle of font, x of text, y of text, color of text, font family of text, the text string we are using)
imagettftext($im, $size, 0, $margin, 12, $color, $font, $text);
// this tells the browser that we want the image to be downloaded instead of displayed
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$im");
header("Content-Type: image/png");
header("Content-Transfer-Encoding: binary");
header('Content-Encoding: binary');
// create the image
imagepng($im);
// frees any memory associated with image
imagedestroy($im);
?>
In step one you created a page (whatever you wanted to call it) and placed the form on it. That form sends data to the page make_it.php.
Step two, which is the page make_it.php, you created the userbar with the power of php and the GD library. Some important things to note here:
The code above is heavily commented, so it should be self explanatory. Remember to add your page URL address (http://......) at the beginning of the code. This is necessary so that if the form user doesn't supply an image to use, they will be redirected to that URL address. As well, if you don't use some of the inputs from the form, you need to either delete those variables or comment them out with double lines: example: //, from the make_it.php code.
Like stated, we have fonts saved in a font folder that users can choose from. If you don't have them available, remove/comment out the font sections of make_it.php.
The above code will look for the image desired to be located in a folder named images. This can be changed easily to wherever your images are stored. This is of course if you are going to have images for users to choose from.
If so, you can set up radio buttons that link to your images if you have a set of images they can choose from.
Overall, this is an easy to use script that took a while to get it to work properly. If you have any questions, don't hesitate in contacting us via our contact page. If you want to see the code in action, visit our homepage at http://www.makeauserbar.com.