在项目中使用Gravatar头像

2009-03-09
Gravatar即Globally Recognized Avatars(个人全球统一标识),简单来说就系一种通用的头像服务,用户只需在Gravatar上注册,绑定一个头像到自己的邮箱地址,那么在所有使 用Gravatar服务的网站(例如WordPress)上使用这个邮箱地址发帖发评论时,头像就会自动贴上,开发者无须自己维护用户的头像数 据~~Gravator服务通过URL调用,提供PHP、JSP、.NET、Python等多种语言的帮助,例如用Python可以这样写:
#import code for encoding urls and generating md5 hashes
import urllib, hashlib

#Set your variables here
email = "someone@somewhere.com"
default = "http://www.somewhere.com/homsar.jpg"
size = 40

#construct the url
gravatar_url = "http://www.gravatar.com/avatar.php?"
gravatar_url += urllib.urlencode({'gravatar_id':hashlib.md5(email).hexdigest(),
'default':default,'size':str(size)})

gravatar_url即为用户someone@somewhere.com的头像路径~~

1 Responses to 在项目中使用Gravatar头像

  1. your blog is very good......

M-OSCAR | Powered by Blogger | Entries (RSS) | Comments (RSS) | Designed by MB Web Design | XML Coded By Cahayabiru.com