Integrating Gravatar with PHP


Gravatar is an image that follows you from site to site appearing beside your name when you do things like comment or post on a blog. Gravatar was started by Tom Preston-Werner but it is now owned by “Automattic” which is the company behind WordPress. Today, there are a many of people using this service. Because using it you can use the same avatar for different websites without even uploading an image to the website.

In simple word, Gravatar is Awesome and integrating Gravatar with PHP is easy too.

Integrating Gravatar with PHP

We are gonna making a simple PHP application that load user avatar associated with email. It is pretty simple process to use Gravatar with PHP. So let’s get start.

function get_avatar($email){
	$size = 164;
	$default = "";
	$avatar = "" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
	return $avatar;

We can fetch avatar from Gravatar using above simple function which will call from <img> element. It convert each email into MD5 hash format so we need to use this hash to load image.

<form method="post" id="formarea">
	<input type="email" value="" placeholder="" name="email" required>
	<input type="submit" value="Show">

Finally we are going to display email associated avatar.

<img id="avatar" src="<?php if( isset($_POST['email']) ){echo get_avatar($_POST['email']); } ?>" alt="Avatar Couldn't Loaded.">

View More Tutorials

Blinking Text with CSS3 and jQuery

Best Photoshop Text Effect Tutorials Collection

Leave a Reply

Your email address will not be published. Required fields are marked *

CSS measuring Units
CSS Web Design

Measurement Units in CSS

CSS offers a number of different units for expressing length. It includes absolute units such as inches, centimeters, points, and so on, as well as relative measures such as percentages and em units. You required these values while specifying various measurements in your stylesheet. It supports various measurement units which are listed below: Using em This measurement […]

Read More
Web Design
Web Design

Upcoming Web Design Trends of 2023

It’s better to stay with time means it’s good idea to update your site to modern web design trends. Every internet folks like responsive design and beautiful themes. If any website was created some years ago i hope it’s probably looking very bad and i say it “Plastic Design” but in present time flat design […]

Read More
Web Design
CSS Web Design

Elegance of Responsive Web Design

It sounds cool as the website that we see in our laptop adjust itself to any device that we could see it clearly, without getting frustrated by broken links and layout. Well that’s why responsive design is making it’s shape in the web industry. Today, web design and development is getting too much flexible in the matter […]

Read More