百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gravatar

> 编程语言
开源

一个用于检索 Gravatar 图像 URL 或检查图像是否存在的 Laravel Gravatar 包。

546 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

一个用于检索 Gravatar 图像 URL 或检查图像是否存在的 Laravel Gravatar 包。

Gravatar for Laravel 5 - 12

Installation

First, pull in the package through Composer via the command line:

javascript
composer require creativeorange/gravatar ~1.0

or add the following to your composer.json file and run composer update.

javascript
"require": {
    "creativeorange/gravatar": "~1.0"
}

Then include the service provider within (Laravel 5.3 or below) app/config/app.php.

php
'providers' => [
    'Creativeorange\Gravatar\GravatarServiceProvider'
];

If using Laravel 5.4, include service provider withing config/app.php

php
'providers' => [
    Creativeorange\Gravatar\GravatarServiceProvider::class
];

If you want to use the facade, add this to de bottom of app/config/app.php And, for convenience, add a facade alias to this same file at the bottom:

php
'aliases' => [
    'Gravatar' => 'Creativeorange\Gravatar\Facades\Gravatar',
];

If you are using Laravel 5.4 or greater, add as follows, add to config/app.php

php
'aliases' => [
    'Gravatar' => Creativeorange\Gravatar\Facades\Gravatar::class,
];

Finally, publish the config by running the php artisan vendor:publish command

Usage

Within your controllers or views, you can use

php
    Gravatar::get('[email protected]');

this will return the URL to the gravatar image of the specified email address. In case of a non-existing gravatar, it will return return a URL to a placeholder image. You can set the type of the placeholder in the configuration option fallback. For more information, visit gravatar.com

Alternatively, you can check for the existence of a gravatar image by using

php
    Gravatar::exists('[email protected]');

This will return a boolean (true or false).

Or you can pass a url to a custom image using the fallback method:

php
    Gravatar::fallback('http://urlto.example.com/avatar.jpg')->get('[email protected]');

Configuration

You can create different configuration groups to use within your application and pass the group name as a second parameter to the get-method:

There is a default group in config/gravatar.php which will be used when you do not specify a second parameter.

If you would like to add more groups, feel free to edit the config/gravatar.php file. For example:

php
return array(
	'default' => array(
		'size'   => 80,
		'fallback' => 'mm',
		'secure' => false,
		'maximumRating' => 'g',
		'forceDefault' => false,
		'forceExtension' => 'jpg',
	),
	'small-secure' => array (
	    'size'   => 30,
	    'secure' => true,
	),
	'medium' => array (
	    'size'   => 150,
	)
);

then you can use the following syntax:

php
Gravatar::get('[email protected]', 'small-secure'); // will use the small-secure group
Gravatar::get('[email protected]', 'medium'); // will use the medium group
Gravatar::get('[email protected]', 'default'); // will use the default group
Gravatar::get('[email protected]'); // will use the default group

Alternatively, you could also pass an array directly as the second parameter as inline options. So, instead of passing a configuration key, you pass an array, which will be merged with the default group:

php
Gravatar::get('[email protected]', ['size'=>200]); 

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言