Creating a FaceBook like profile badge

You know what a facebook profile badge is, right? (if no, just look here on sidebar my facebook profile badge). Well creating a profile badge like that is really easy. Here i created a small script to show the basic of how this thing works. So, here is the profile badge class

class profile_badge{
	public static function calc_image_height($strs,$limit){

		foreach($strs as $str){

	return ($total_line*15)+40;

	public static function get_badge($text_name,$text_email){





	imagecopymerge ($bg,$im,0,0,0,0,$width,$height,100);

	imagefilledrectangle ($bg,0,$height,$width,$height+$extra,$white);
	imagerectangle ($bg,0,0,$width-1,$height+$extra-1,$bdr);

	imagettftext($bg, 10,0,5, $text_pos, $black, $font, $label_name);

		imagettftext($bg, 10,0,5, $text_pos, $gray, $font, $text_name);
		foreach($name_array as $text_name){
			imagettftext($bg, 10,0,5, $text_pos, $gray, $font, $text_name);

	imagettftext($bg, 10,0,5, $text_pos, $black, $font, $label_email);

		imagettftext($bg, 10,0,5, $text_pos, $gray, $font, $text_email);
		foreach($email_array as $text_email){
			imagettftext($bg, 10,0,5, $text_pos, $gray, $font, $text_email);

	return $bg;


Notice, at line 25, yes that’s my site’s logo image url. Also notice at line 43, yes this my font file. you can use your own font of choice in there. Ok now include that class and call its get_badge function, this way,

$name='Mahabubul Hasan';


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

and it generates a output like this:

isn’t it cool? 😉


About uzzal

Software developer
This entry was posted in php, web design and tagged , . Bookmark the permalink.

2 Responses to Creating a FaceBook like profile badge

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s