├── LICENSE.md ├── README.md ├── composer.json ├── config └── gravatar.php └── src └── helpers.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2022 Elf Sundae 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Gravatar Helper 2 | 3 | 4 | 5 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/elfsundae/laravel-gravatar.svg?style=flat-square)](https://packagist.org/packages/elfsundae/laravel-gravatar) 6 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 7 | [![tests](https://github.com/ElfSundae/laravel-gravatar/actions/workflows/tests.yml/badge.svg)](https://github.com/ElfSundae/laravel-gravatar/actions/workflows/tests.yml) 8 | [![SymfonyInsight Grade](https://img.shields.io/symfony/i/grade/6e213f0f-e618-4ba5-b252-2575d18f21a9?style=flat-square)](https://insight.symfony.com/projects/6e213f0f-e618-4ba5-b252-2575d18f21a9) 9 | [![Quality Score](https://img.shields.io/scrutinizer/g/ElfSundae/laravel-gravatar.svg?style=flat-square)](https://scrutinizer-ci.com/g/ElfSundae/laravel-gravatar) 10 | [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/ElfSundae/laravel-gravatar/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/ElfSundae/laravel-gravatar/?branch=master) 11 | [![Total Downloads](https://img.shields.io/packagist/dt/elfsundae/laravel-gravatar.svg?style=flat-square)](https://packagist.org/packages/elfsundae/laravel-gravatar) 12 | 13 | The easiest way to generate [Gravatar](https://gravatar.com) avatar URL, with multiple connections support. 14 | 15 | ## Installation 16 | 17 | You can install this package using the [Composer](https://getcomposer.org) manager: 18 | 19 | ```sh 20 | $ composer require elfsundae/laravel-gravatar 21 | ``` 22 | 23 | Then copy the [configuration file](config/gravatar.php) to your application: 24 | 25 | ```sh 26 | $ cp vendor/elfsundae/laravel-gravatar/config/gravatar.php config/gravatar.php 27 | ``` 28 | 29 | For Lumen, you need to load the configuration file in your `bootstrap/app.php` : 30 | 31 | ```php 32 | $app->configure('gravatar'); 33 | ``` 34 | 35 | ## API 36 | 37 | [`gravatar()`](src/helpers.php) is a global helper function you can use anywhere. 38 | 39 | ```php 40 | /** 41 | * Generate Gravatar avatar URL for the given email address. 42 | * 43 | * @param string $email Email or email hash 44 | * @param string|int $connection Connection name or image size 45 | * @param string|int $size Connection name or image size 46 | * @return string 47 | */ 48 | function gravatar($email, $connection = 'default', $size = null) 49 | ``` 50 | 51 | ## Usage 52 | 53 | ```php 54 | // For an email address, using the "default" connection configuration 55 | gravatar('foo@example.com'); 56 | 57 | // For an email MD5 hash, using the "default" connection configuration 58 | gravatar('b48def645758b95537d4424c84d1a9ff'); 59 | 60 | // Using the "large" connection 61 | gravatar($email, 'large'); 62 | 63 | // Using the "default" connection, and overriding "size" parameter to 100 64 | gravatar($email, 100); 65 | 66 | // Using the "avatar" connection, and overriding "size" parameter to 100 67 | gravatar($email, 'avatar', 100); 68 | gravatar($email, 100, 'avatar'); 69 | ``` 70 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elfsundae/laravel-gravatar", 3 | "type": "library", 4 | "description": "The easiest way to generate Gravatar avatar URL.", 5 | "keywords": ["laravel", "gravatar", "helper"], 6 | "homepage": "https://github.com/ElfSundae/laravel-gravatar", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Elf Sundae", 11 | "email": "elf.sundae@gmail.com", 12 | "homepage": "https://0x123.com" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.6.4", 17 | "illuminate/support": "~5.0|~6.0|~7.0|~8.0|~9.0" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "~5.7|~6.0|~7.0|~8.0|~9.0", 21 | "orchestra/testbench": "~3.0|~4.0|~5.0|~6.0|~7.0" 22 | }, 23 | "autoload": { 24 | "files": [ 25 | "src/helpers.php" 26 | ] 27 | }, 28 | "scripts": { 29 | "test": "vendor/bin/phpunit" 30 | }, 31 | "minimum-stability": "dev", 32 | "prefer-stable": true 33 | } 34 | -------------------------------------------------------------------------------- /config/gravatar.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'size' => 120, 31 | ], 32 | 33 | 'small' => [ 34 | 'size' => 40, 35 | ], 36 | 37 | 'large' => [ 38 | 'size' => 460, 39 | ], 40 | 41 | ]; 42 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 |