Using Laravel to generate an elegant method for Gravatar Avatar address, laravelgravatar

Source: Internet
Author: User
Tags md5 hash

Using Laravel to generate an elegant method for Gravatar Avatar address, laravelgravatar

Preface

Gravatar profile pictures have become a very popular profile picture for blogs, forums, and so on, whether it is Wordpress, Z-Blog, Typecho, Emlog, etc. Gravatar profile pictures are supported for messages or login registration, the Laravel Gravatar extension package provides the simplest and most elegant way to generate Gravatar globally recognized Avatar addresses. The flexible and convenient API supports multi-connection configuration and image address.

Project home: https://github.com/ElfSundae/laravel-gravatar

Install

$ composer require elfsundae/laravel-gravatar

Configuration

Although this extension package can be used without any settings, in order not to hard-encode image size and other parameters in the code, and to use the image address (You know ), therefore, we recommend that you use the configuration file to configure the Gravatar connection ).

For performance, this extension package does not register a service provider, so you need to manually copy the configuration file to your application:

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

The configuration file has detailed notes. Please read them yourself.

In the configuration file, you can configure multiple Gravatar connections for your application. In addition to the Gravatar image parameters (see the https://en.gravatar.com/site/implement/images/), you can also set the url image address. The default connection name is default.

Configuration example:

'default' => [ 'url' => 'https://gravatar.cat.net/avatar', 'size' => 120,],'small' => [ 'url' => 'https://gravatar.cat.net/avatar', 'size' => 40,],'large' => [ 'url' => 'https://gravatar.cat.net/avatar', 'size' => 460,],

API

There is only one global help 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 = null)

Example

// Generate an avatar address for the email, and configure gravatar ('foo @ example.com ') using the "default" connection; // generate an avatar address for the MD5 Hash Value of the email, use "default" to connect to gravatar ('b48def645758b95537d4424c84d1a9ff '); // use "large" to connect to gravatar ($ email, 'large'); // use "default" to connect to configuration, and overwrite the size parameter 100 gravatar ($ email, 100); // use "avatar" to connect to the configuration, and overwrite the size parameter 100 gravatar ($ email, 'Avatar ', 100); // or: gravatar ($ email, 100, 'Avatar ');

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

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: info-contact@alibabacloud.com 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.