PHP Magic Book – Free PHP Scripts, Tutorials and Downloads, PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips

Enable Gravatar/Avatar at Your Website – Gravatar Image PHP Script

gravatarYou might have already created an account at gravatar (Globally Recognized Avatars) and enjoying your display picture or avatar at forums and blogs when you just post your comment with your email and there you are — it displays your avatar along with your comment. If you are a developer and you create websites – PHP websites – and wondering how you can enable gravatars / avatars in your next project then here is very easy to use working solution – PHP script to enable gravatar at your PHP website / blog / forum / project.

Copy the following code. Paste it in a file, save it in PHP extension, upload it or use it at localhost – just change the usersEmail value to your email address, if you are already at gravatars website and hit it. Other instructions for customization of script – you can find in the script. e.g. size of gravatar, default image, rating etc.

Gravatars PHP Script for Your Website

<?php
// The users email, passed to Gravatar
$usersEmail = "myemail@live.com";
 
// default avatar to load if Gravatar doesn't find one
$defaultImage = "http://domain.com/default.png";
 
// The size of the image
$avatarSize = "50";
 
// Minimum rating for your site
// Possible values (G, PG, R, X)
$avatarRating = "G";
 
// Border around the image
$avatarBorder = "000000";
 
// URL for Gravatar
$gravatarURL = "http://www.gravatar.com/avatar.php?gravatar_id=%s&default=%s&size=%s&border=%s&rating=%s";
 
$avatarURL = sprintf
(
	$gravatarURL,
	md5($usersEmail),
	$defaultImage,
	$avatarSize,
	$avatarBorder,
	$avatarRating
);
 
print "<img src="" .
	$avatarURL . "" width="" .
	$avatarSize . "" height="" .
	$avatarSize . "" />";
?>
  • Share/Bookmark
Tags: , , , ,
Posted in: Scripts, Useful Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts




Post a Comment

  Subscribe Via RSS
  Subscribe Via Email