How to create a GRAVATAR image URL from a given email address

Is there an easy way with php , simple script processing or a url to create a url for a gravatar image matching email?

Ex. http://gravatar.com/avatars/ avatar.php?email=myemail@myserver.com Ex. http://gravatar.com/avatars/ avatar.php?email=myemail@myserver.com , and this returns a jpeg or png image.

If there is no easy way, as an example, then what is the easiest way you know to allow the gravatar URL corresponding to the email ?. Thanks

+6
php gravatar
source share
4 answers

You can find a sample script with PHP code on your implementation site: http://en.gravatar.com/site/implement/php

+7
source share

Use this:

 $userMail = whatever_to_get_the_email; $imageWidth = '150'; //The image size $imgUrl = 'http://www.gravatar.com/avatar/'.md5($userMail).'fs='.$imageWidth; 
+8
source share

The root script is located at http://www.gravatar.com/avatar/ The next part of the URL is a hexadecimal hash of the MD5 file of the requested downstream email address of the user with all spaces trimmed. You can add the correct file extension, but it is optional.

The full API is here http://en.gravatar.com/site/implement/

+4
source share

Although @ dipi-evil's solution works fine, I didn't get any more images with it. This is how I started working correctly.

 $userMail = ' johndoe@example '; $imageWidth = '600'; //The image size $imgUrl = 'https://secure.gravatar.com/avatar/'.md5($userMail).'?size='.$imageWidth; 
+1
source share

All Articles