elfsundae/laravel-gravatar

生成 Gravatar 头像 URL 的最简单方式。

2.6.0 2022-02-19 22:42 UTC

This package is auto-updated.

Last update: 2024-09-20 04:23:55 UTC


README

Latest Version on Packagist Software License tests SymfonyInsight Grade Quality Score Code Coverage Total Downloads

生成 Gravatar 头像 URL 的最简单方式,支持多连接。

安装

您可以使用 Composer 管理器安装此包

$ composer require elfsundae/laravel-gravatar

然后将 配置文件 复制到您的应用程序中

$ cp vendor/elfsundae/laravel-gravatar/config/gravatar.php config/gravatar.php

对于 Lumen,您需要在 bootstrap/app.php 中加载配置文件

$app->configure('gravatar');

API

gravatar() 是一个全局辅助函数,您可以在任何地方使用。

/**
 * Generate Gravatar avatar URL for the given email address.
 *
 * @param  string      $email       Email or email hash
 * @param  string|int  $connection  Connection name or image size
 * @param  string|int  $size        Connection name or image size
 * @return string
 */
function gravatar($email, $connection = 'default', $size = null)

用法

// For an email address, using the "default" connection configuration
gravatar('foo@example.com');

// For an email MD5 hash, using the "default" connection configuration
gravatar('b48def645758b95537d4424c84d1a9ff');

// Using the "large" connection
gravatar($email, 'large');

// Using the "default" connection, and overriding "size" parameter to 100
gravatar($email, 100);

// Using the "avatar" connection, and overriding "size" parameter to 100
gravatar($email, 'avatar', 100);
gravatar($email, 100, 'avatar');