Gravatar :有默认图像吗?

发布于 2024-08-29 08:36:07 字数 123 浏览 9 评论 0原文

我已经为正在构建的门户实现了 gravatar,并且想知道 gravatar 是否有默认图像 URL?并非所有访问该网站的人都已登录或拥有电子邮件地址,在这种情况下,是否有可以显示的默认图像(可通过 gravatar url 访问)

I have implemented gravatar for a portal I am building and wanted to know if there is a default image URL for gravatar? Not all people who visit the site are logged in or have email addresses, in such a case, is there a default image that can be shown (accessible via gravatar url)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北笙凉宸 2024-09-05 08:36:07

要选择默认图像,您可以使用 d 参数:

https://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802?d=identicon

或不使用哈希:

https://www.gravatar.com/avatar/?d=identicon

或不使用 d 参数:

https://www.gravatar.com/avatar

来源:gravatar.com

To select a default image, you can use the d parameter:

https://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802?d=identicon

Or without a hash:

https://www.gravatar.com/avatar/?d=identicon

Or without the d parameter:

https://www.gravatar.com/avatar

Source: gravatar.com.

任性一次 2024-09-05 08:36:07

Gravatar 在此处描述了默认图像的选项:http://en.gravatar.com/site/implement /images/

您可以通过将适当的名称/值对添加到您的网址来选择您想要的选项。例如,您可以使用“神秘人”(d=mp),如下所示:

上面的图像是使用以下命令创建的网址 http://www.gravatar.com/avatar/?d=mp。请注意,电子邮件哈希字符串已被省略,但通常您会将其包含在请求中。

上述链接中列出的选项:

  • 404:如果没有图像与电子邮件哈希关联,则不加载任何图像,而是返回 HTTP 404(未找到文件)响应
  • mp:(神秘人)一个简单的卡通风格的人物轮廓(不因电子邮件哈希值而变化)
  • identicon:基于电子邮件哈希的几何图案
  • monsterid:生成的具有不同颜色、面孔等的“怪物”
  • wavatar:生成具有不同特征和背景的面孔
  • 复古:令人惊叹的生成、8 位街机风格像素化面孔
  • robohash:生成的具有不同颜色、面孔等的机器人
  • 空白:透明 PNG 图像(出于演示目的,将边框添加到下面的 HTML 中)

如您所愿,也可以使用尺寸选项 s=更改默认图像的大小。

在此处输入图像描述

上面的图像是使用 http://www.gravatar.com/avatar/? 创建的d=retro&s=32

感谢 @Alireza Rezaee 更新了图像类型。

Gravatar describe the options for default images here: http://en.gravatar.com/site/implement/images/

You can select which option you want by adding the appropriate name/value pair to your url. For example, you could use "mystery person" (d=mp) which looks like this:

The above image was created with the url http://www.gravatar.com/avatar/?d=mp. Note that the email hash string has been omitted but normally you would include it as part of the request.

Options listed at the above link:

  • 404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
  • mp: (mystery-person) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
  • identicon: a geometric pattern based on an email hash
  • monsterid: a generated 'monster' with different colors, faces, etc
  • wavatar: generated faces with differing features and backgrounds
  • retro: awesome generated, 8-bit arcade-style pixelated faces
  • robohash: a generated robot with different colors, faces, etc
  • blank: a transparent PNG image (border added to HTML below for demonstration purposes)

As you would hope, using the size option s=<pixels> also changes the size of the default image.

enter image description here

The above image was created with http://www.gravatar.com/avatar/?d=retro&s=32

Thanks to @Alireza Rezaee for the updated image types.

西瑶 2024-09-05 08:36:07

您还可以使用默认/后备头像的自定义 URL。但是,自定义 URL 必须指向公开可用的图像,否则将不会显示。您可以在此处gravatar.com

这是我在处理头像图像时使用的 PHP 函数。

function myprefix_get_gravatar_url( $email, $default='mm', $size=92 )
{
    $email = md5( strtolower( trim( $email ) ) );
    $default = urlencode( $default );
    $size = (int)$size;

    $url = 'http://www.gravatar.com/avatar/';
    if ( is_ssl() )
        $url = 'https://secure.gravatar.com/avatar/';

    return $url.$email."?d=".$default."&s=".$size;
}

用法示例:

$img2x = myprefix_get_gravatar_url( 
    '[email protected]',
    'https://www.google.com/images/srpr/logo11w.png',
    184
);

You can also use a custom URL for the default/fallback avatar. However, the custom URL must point to a publicly available image or else it wont show. You can learn more here and at gravatar.com.

Here is a PHP function I use to when working with gravatar images.

function myprefix_get_gravatar_url( $email, $default='mm', $size=92 )
{
    $email = md5( strtolower( trim( $email ) ) );
    $default = urlencode( $default );
    $size = (int)$size;

    $url = 'http://www.gravatar.com/avatar/';
    if ( is_ssl() )
        $url = 'https://secure.gravatar.com/avatar/';

    return $url.$email."?d=".$default."&s=".$size;
}

Example usage:

$img2x = myprefix_get_gravatar_url( 
    '[email protected]',
    'https://www.google.com/images/srpr/logo11w.png',
    184
);
記憶穿過時間隧道 2024-09-05 08:36:07

不完全是,不。这没有抓住 Gravatar 服务的重点。它的设计目的是让您的用户可以注册他们的电子邮件地址并将头像图像与其相关联。然后,您的网站(和其他网站)可以查询 Gravatar 以返回与相关电子邮件地址关联的图像。

如果您希望向甚至不在您的网站上输入电子邮件地址的用户显示图像,我可以看到两种解决方案:

  1. 使用您自己的代码执行此操作。当您处理没有电子邮件地址的用户时,您可以只输出您自己选择的默认图像。当然,这意味着它不会使用头像地址来完成,并且它将是您需要为自己提供服务的东西。
  2. 自己注册一个专用于没有/输入自己的电子邮件地址的用户。例如,您可以注册类似 [email] ;受保护]< /code> 然后将其注册到 Gravatar 服务并将您选择的默认图像与其关联。在构建图像 URL 时,您自己的应用程序代码仍然需要输出适当的头像 URL,以替换此电子邮件地址来代替用户不存在的电子邮件地址,但它将允许您使用您所要求的头像 URL。

Not really, no. That is missing the point of the Gravatar service. It is designed so that your users can register their email address(es) and associate a gravatar image with it/them. Your site (and other sites) can then query Gravatar to give back the image which is associated with the email address in question.

If you want an image showing for users who do not even enter an email address on your website, you have two solutions that I can see:

  1. Do it in your own code. When you are dealing with a user who has no email address, you can just output a default image of your own choosing. Of course, this means it will not be done using a gravatar address and it'll be something you'll need to be serving yourself.
  2. Register an email address yourself dedicated to users who do not have/enter their own. For example, you could register something like [email protected] and then register this with the Gravatar service and associate your chosen default image with this. Your own app code will still need to output the appropriate gravatar URL substituting this email address in place of the user's non-existant one when constructing the image URL, but it will allow you to use a gravatar URL which is something you have asked for.
久伴你 2024-09-05 08:36:07

对于那些只想链接到给定电子邮件图像的人(这并不能解决 OP 的请求,但此页面在网络搜索中很突出):从几乎任何 POSIX shell,您都可以为“[email protected]" 为:

echo "http://gravatar.com/avatar/$(echo -n [email protected] | md5sum | awk '{print $1}')?s=256"

您确实需要考虑足够多的内容来替换 [email protected] 包含有问题的电子邮件。我添加了“?s=256”来展示如何指定大小。

我需要这个来向某人说明什么是头像。

For those who just want a link to a given email's image (this does not address the OP's request, but this page is prominent in web searches): From almost any POSIX shell you can generate the 256 pixel gravatar URL for "[email protected]" with:

echo "http://gravatar.com/avatar/$(echo -n [email protected] | md5sum | awk '{print $1}')?s=256"

You do need to think enough to replace [email protected] with the email in question. I included the "?s=256" to show how to specify the size.

I needed this to illustrate to somebody what a gravatar is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文