How to generate the random default “gravatars” like on Stack Overflow?

落爺英雄遲暮 提交于 2019-11-28 18:34:54

问题


How does Stack Overflow auto-generate the gravatars for those users who do not upload a picture or who have not created a Gravatar icon?

Where do these random avatars come from, and how can I generate them for my own site?


回答1:


The 'random' colorful gravatars are displayed because this query string parameter is being added to every gravatar source URL: d=identicon

This is done so that if the user doesn't have a gravatar image associated with his email, this 'random' image is displayed, instead of the default blue gravatar image.

The following displays the 'default' blue image because the parameter is not included:

Yet, the same URL with the d=identicon parameter included, shows this:

This is the URL used for the example: https://www.gravatar.com/avatar/94d093eda664addd6e450d7e9881bcad?s=32&d=identicon&r=PG

By the way these images (called Identicons) are not really random, but are generated based on the email hash.

See How is the default user avatar generated? for some Language Implementations of this algorithm.



来源:https://stackoverflow.com/questions/405717/how-to-generate-the-random-default-gravatars-like-on-stack-overflow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!