├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── docs └── images │ ├── profile-font-roboto.png │ ├── profile-small.png │ └── profile.png ├── font └── OpenSans-Semibold.ttf ├── phpunit.xml └── src └── A6digital └── Image ├── DefaultProfileImage.php ├── DefaultProfileImageServiceProvider.php └── Facades └── DefaultProfileImage.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | - 5.6 8 | - hhvm 9 | 10 | before_script: 11 | - curl -s http://getcomposer.org/installer | php 12 | - php composer.phar install --dev 13 | 14 | script: vendor/bin/phpunit --coverage-text -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 A6 Digital 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Default Profile Image 2 | [![Latest Stable Version](https://poser.pugx.org/a6digital/laravel-default-profile-image/v/stable.svg)](https://packagist.org/packages/a6digital/laravel-default-profile-image) [![Total Downloads](https://poser.pugx.org/a6digital/laravel-default-profile-image/downloads.svg)](https://packagist.org/packages/a6digital/laravel-default-profile-image) [![Latest Unstable Version](https://poser.pugx.org/a6digital/laravel-default-profile-image/v/unstable.svg)](https://packagist.org/packages/a6digital/laravel-default-profile-image) [![License](https://poser.pugx.org/a6digital/laravel-default-profile-image/license.svg)](https://packagist.org/packages/a6digital/laravel-default-profile-image) 3 | 4 | Laravel package to create default profile image using name of user. 5 | 6 | 7 | ## Installation 8 | 9 | Install using composer: 10 | 11 | composer require a6digital/laravel-default-profile-image 12 | 13 | Edit `app/config/app.php` and add the `providers` 14 | 15 | 'providers' => [ 16 | 'A6digital\Image\DefaultProfileImageServiceProvider' 17 | ] 18 | 19 | 20 | ## Basic Usage 21 | 22 | To create a profile image just do 23 | 24 | $img = \DefaultProfileImage::create("Name Surname"); 25 | \Storage::put("profile.png", $img->encode()); 26 | 27 | 28 | This will create a profile image that has 512px width&height using the first letters of name and surname. 29 | 30 | ![Profile Image](https://raw.githubusercontent.com/a6digital/laravel-default-profile-image/master/docs/images/profile.png) 31 | 32 | ## Advanced Usage 33 | 34 | Create a white color text over black color background profile image that has 216px width&height. 35 | 36 | $img = \DefaultProfileImage::create("Name Surname", 256, '#000', '#FFF'); 37 | \Storage::put("profile.png", $img->encode()); 38 | 39 | ![Profile Small Image](https://raw.githubusercontent.com/a6digital/laravel-default-profile-image/master/docs/images/profile-small.png) 40 | 41 | 42 | Using a custom font 43 | 44 | $img = \DefaultProfileImage::create("@ Lamoni", 256, "#212121", "#FFF", '/var/www/public/fonts/RobotoDraftRegular.woff'); 45 | \Storage::put("profile.png", $img->encode()); 46 | 47 | ![Profile Small Image](https://raw.githubusercontent.com/a6digital/laravel-default-profile-image/master/docs/images/profile-font-roboto.png) -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "a6digital/laravel-default-profile-image", 3 | "description" : "Laravel package to create default profile image using name of user.", 4 | "type" : "laravel-library", 5 | "authors" : [{ 6 | "name" : "Hasan Toprakkaya", 7 | "email" : "hasan@a6digital.com" 8 | } 9 | ], 10 | "minimum-stability": "dev", 11 | "keywords" : [ 12 | "laravel default profile image" 13 | ], 14 | "homepage" : "https://github.com/a6digital/laravel-default-profile-image", 15 | "license" : [ 16 | "MIT" 17 | ], 18 | "require" : { 19 | "php" : ">=5.4.0", 20 | "intervention/image": "2.*" 21 | }, 22 | "require-dev" : { 23 | }, 24 | "autoload" : { 25 | "psr-0" : { 26 | "A6digital\\Image" : "src/" 27 | } 28 | }, 29 | "support" : { 30 | "source" : "https://github.com/a6digital/laravel-default-profile-image", 31 | "issues" : "https://github.com/a6digital/laravel-default-profile-image/issues" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/images/profile-font-roboto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socialityio/laravel-default-profile-image/92f46d2f72100959e549b50ba1bc34270dc47d98/docs/images/profile-font-roboto.png -------------------------------------------------------------------------------- /docs/images/profile-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socialityio/laravel-default-profile-image/92f46d2f72100959e549b50ba1bc34270dc47d98/docs/images/profile-small.png -------------------------------------------------------------------------------- /docs/images/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socialityio/laravel-default-profile-image/92f46d2f72100959e549b50ba1bc34270dc47d98/docs/images/profile.png -------------------------------------------------------------------------------- /font/OpenSans-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socialityio/laravel-default-profile-image/92f46d2f72100959e549b50ba1bc34270dc47d98/font/OpenSans-Semibold.ttf -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | ../src/ 20 | 21 | 22 | 23 | 24 | ./tests/ 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/A6digital/Image/DefaultProfileImage.php: -------------------------------------------------------------------------------- 1 | 2) { 46 | $str = $words[0][0].$words[2][0]; 47 | } else if (count($words) == 2) { 48 | $str = $words[0][0].$words[1][0]; 49 | } else { 50 | $str = substr($name_ascii, 0, 2); 51 | } 52 | 53 | $img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function($font) use($size, $text_color, $font_file) { 54 | $font->file($font_file); 55 | $font->size($size / 2); 56 | $font->color($text_color); 57 | $font->align('center'); 58 | $font->valign('middle'); 59 | }); 60 | 61 | return $img; 62 | 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/A6digital/Image/DefaultProfileImageServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('defaultprofileimage', function($app) 20 | { 21 | return new DefaultProfileImage; 22 | }); 23 | 24 | // Shortcut so developers don't need to add an Alias in app/config/app.php 25 | $this->app->booting(function() 26 | { 27 | $loader = \Illuminate\Foundation\AliasLoader::getInstance(); 28 | $loader->alias('DefaultProfileImage', 'A6digital\Image\Facades\DefaultProfileImage'); 29 | }); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/A6digital/Image/Facades/DefaultProfileImage.php: -------------------------------------------------------------------------------- 1 |