|
| 1 | +# Laravel Favicon |
| 2 | + |
| 3 | +[](https://packagist.org/packages/beyondcode/laravel-favicon) |
| 4 | +[](https://travis-ci.org/beyondcode/laravel-favicon) |
| 5 | +[](https://scrutinizer-ci.com/g/beyondcode/laravel-favicon) |
| 6 | +[](https://packagist.org/packages/beyondcode/laravel-favicon) |
| 7 | + |
| 8 | +Create dynamic favicons based on your environment settings. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +You can install the package via composer: |
| 15 | + |
| 16 | +```bash |
| 17 | +composer require beyondcode/laravel-favicon |
| 18 | +``` |
| 19 | + |
| 20 | +The service provider for this package will be automatically registered for you. |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +To make use of this package, make use of the `favicon` helper function that this package provides. |
| 25 | + |
| 26 | +You can simply wrap the function around your favicon icon names, like this: |
| 27 | + |
| 28 | +```html |
| 29 | +<link rel="icon" type="image/png" sizes="32x32" href="{{ favicon(asset('favicon-32x32.png')) }}"> |
| 30 | + |
| 31 | +<link rel="shortcut icon" href="{{ favicon('favicon.ico') }}" /> |
| 32 | +``` |
| 33 | + |
| 34 | +## Customization |
| 35 | + |
| 36 | +You can completely customize which environments you want to have enabled for the favicon generation, as well as the font and colors that will be used. |
| 37 | + |
| 38 | +To modify the default values, publish the package configuration file using: |
| 39 | + |
| 40 | +``` |
| 41 | +php artisan vendor:publish --provider='BeyondCode\LaravelFavicon\FaviconServiceProvider' --tag='config' |
| 42 | +``` |
| 43 | + |
| 44 | +This will publish the `config/favicon.php` file. |
| 45 | + |
| 46 | +This is what the default content looks like: |
| 47 | + |
| 48 | +```php |
| 49 | +return [ |
| 50 | + |
| 51 | + /* |
| 52 | + * The list of enabled environments for the dynamic favicon |
| 53 | + * generation. You can specify the text to display as well |
| 54 | + * as the font and background color for the text. |
| 55 | + * |
| 56 | + * If no background color is specified, the text will be |
| 57 | + * on a transparent background. |
| 58 | + */ |
| 59 | + 'enabled_environments' => [ |
| 60 | + 'local' => [ |
| 61 | + 'text' => 'DEV', |
| 62 | + 'color' => '#000000', |
| 63 | + 'background_color' => '#ffffff', |
| 64 | + ], |
| 65 | + ], |
| 66 | + |
| 67 | + /* |
| 68 | + * The dynamic favicon text padding to apply. |
| 69 | + */ |
| 70 | + 'padding' => [ |
| 71 | + 'x' => 2, |
| 72 | + 'y' => 2, |
| 73 | + ], |
| 74 | + |
| 75 | + /* |
| 76 | + * The font file to use for the dynamic favicon generation. |
| 77 | + * The default value will use OpenSans Regular. |
| 78 | + */ |
| 79 | + 'font' => null, |
| 80 | + |
| 81 | + /* |
| 82 | + * Intervention Image supports "GD Library" and "Imagick" to process images |
| 83 | + * internally. You may choose one of them according to your PHP |
| 84 | + * configuration. By default PHP's "GD Library" implementation is used. |
| 85 | + * |
| 86 | + * If you want to convert ICO files, you need to use imagick. |
| 87 | + * |
| 88 | + * Supported: "gd", "imagick" |
| 89 | + * |
| 90 | + */ |
| 91 | + 'image_driver' => 'gd', |
| 92 | + |
| 93 | + /* |
| 94 | + * The prefix to use for the dynamic favicon URL. |
| 95 | + */ |
| 96 | + 'url_prefix' => 'laravel-favicon', |
| 97 | + |
| 98 | + /* |
| 99 | + * The favicon generator class to use. The default generator |
| 100 | + * makes use of the environment settings defined in this file. |
| 101 | + * But you can create your own favicon generator if you want. |
| 102 | + */ |
| 103 | + 'generator' => \BeyondCode\LaravelFavicon\Generators\EnvironmentGenerator::class, |
| 104 | + |
| 105 | + |
| 106 | +]; |
| 107 | +``` |
| 108 | + |
| 109 | +Modify the settings to suit your needs. |
| 110 | + |
| 111 | +## Custom generator |
| 112 | + |
| 113 | +The default favicon generator will write the text on the bottom-right corner of your favicon, in the desired color, font and background-color. |
| 114 | +If you want to generate a completely custom favicon, you can create your own FaviconGenerator implementation class and set it in the configuration file. |
| 115 | + |
| 116 | +This is the interface that the generator should implement: |
| 117 | + |
| 118 | +```php |
| 119 | +interface FaviconGenerator |
| 120 | +{ |
| 121 | + public function generate(string $icon): Response; |
| 122 | + |
| 123 | + public function shouldGenerateFavicon(): bool; |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +The `generate` method receives the icon url/filename and expects you to return an illuminate HTTP response. |
| 128 | + |
| 129 | +The `shouldGenerateFavicon` method can be used to determine if a custom favicon should get generated. |
| 130 | + |
| 131 | +## FAQ |
| 132 | + |
| 133 | +- My ICO files are not working, why? |
| 134 | + |
| 135 | +In order to modify ICO files, you need the Imagick PHP library installed and enabled in your `config/favicon.php` file. |
| 136 | + |
| 137 | +- Is there a performance impact when I'm using this package? |
| 138 | + |
| 139 | +No - the default generator only modifies your favicon when the specified environment is enabled. This means, that production environments only see the static assets that you already have. |
| 140 | + |
| 141 | +### Changelog |
| 142 | + |
| 143 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 144 | + |
| 145 | +## Contributing |
| 146 | + |
| 147 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 148 | + |
| 149 | +### Security |
| 150 | + |
| 151 | +If you discover any security related issues, please email [email protected] instead of using the issue tracker. |
| 152 | + |
| 153 | +## Credits |
| 154 | + |
| 155 | +- [Marcel Pociot](https://github.com/mpociot) |
| 156 | +- [All Contributors](../../contributors) |
| 157 | + |
| 158 | +## License |
| 159 | + |
| 160 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments