Method of generating Gravatar avatar address using Laravel

Source: Internet
Author: User
Tags md5 hash
Gravatar is an image that follows the site you visited, and when you leave a message or post in your blog, it will appear next to your name. The following article mainly introduces you to the use of laravel how to generate Gravatar Avatar address elegant method, the need for friends can refer to.


Gravatar Avatar has become a blog, forum, such as a very popular general picture, whether it is WordPress or Z-blog, Typecho, emlog, such as messages or login registration support Gravatar Avatar, Laravel Gravatar The expansion pack provides the simplest and most elegant way to generate Gravatar global accepted avatar addresses. Flexible and convenient API, support multi-connection configuration, support image address.

Project home: Https://


$ composer require Elfsundae/laravel-gravatar


Although this expansion pack does not require any setup, it is recommended to use a configuration file to configure the Gravatar connection (connection) in order to not hardcode parameters such as picture size in your code, and to use a mirrored address (you understand).

For performance, this expansion pack does not register service provider, so you need to manually copy the configuration file to your app:

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

The configuration file has a very detailed comment, please read it yourself.

In the configuration file you can configure multiple Gravatar connections (connection) for your app, in addition to the Gravatar picture parameters (see, You can also set the URL mirroring address. The default name of the connection is default.

Example configuration:

' Default ' = = [' url ' = ' ', ' size ' = ' + ',], ' small ' + [' url ' = ' + ' https://g ', ' size ' = +,], ' large ' + = [' url ' = ' ', ' size ' = 46 0,],


There is only one global helper function: 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 = nul L

Using the example

Generate an avatar address for email, use "Default" connection to configure Gravatar (' '),//To generate an avatar address for the MD5 hash of the email, configure Gravatar with "default" connection (' B48de F645758b95537d4424c84d1a9ff ');//Use "large" Connection configuration Gravatar ($email, ' large ');//Use the "default" Connection configuration and override the size parameter to 100gravatar ( $email, 100);//Use the "Avatar" Connection configuration and overwrite the size parameter to 100gravatar ($email, ' Avatar ', 100);//or: Gravatar ($email, +, ' Avatar ');


Talk about the usage of public,private,protected,abstract and other keywords in PHP

PHP lets you make a new array instance with the same values in the array

Troubleshooting PHP string Length inconsistencies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.