beyondcode / laravel-favicon
根据环境设置创建动态favicon。
1.6.0
2024-05-21 10:39 UTC
Requires
- php: ^7.1|^8.0|^8.1|^8.2|^8.3
- illuminate/http: 5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*|^10.0|^11.0
- illuminate/support: 5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*|^10.0|^11.0
- intervention/image: ^2.4
Requires (Dev)
- orchestra/testbench: ^3.7|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^7.0|^8.0|^9.0|^10.0|^11.0
README
根据环境设置创建动态favicon。
Laravel包开发
如果您想学习如何自己创建可重用的PHP包,请查看我即将推出的PHP包开发视频课程。
安装
您可以通过composer安装此包
composer require beyondcode/laravel-favicon
此包的服务提供者将自动为您注册。
兼容性
用法
要使用此包,请使用此包提供的favicon
辅助函数。
您可以将函数简单地包装在favicon图标名称周围,如下所示
<link rel="icon" type="image/png" sizes="32x32" href="{{ favicon(asset('favicon-32x32.png')) }}"> <link rel="shortcut icon" href="{{ favicon('favicon.ico') }}" />
自定义
您可以根据需要完全自定义要启用favicon生成的环境,以及将使用的字体和颜色。
要修改默认值,请使用以下命令发布包配置文件
php artisan vendor:publish --provider='BeyondCode\LaravelFavicon\FaviconServiceProvider' --tag='config'
这将发布config/favicon.php
文件。
默认内容如下所示
return [ /* * The list of enabled environments for the dynamic favicon * generation. You can specify the text to display as well * as the font and background color for the text. * * If no background color is specified, the text will be * on a transparent background. */ 'enabled_environments' => [ 'local' => [ 'text' => 'DEV', 'color' => '#000000', 'background_color' => '#ffffff', ], ], /* * The dynamic favicon text padding to apply. */ 'padding' => [ 'x' => 2, 'y' => 2, ], /* * The font file to use for the dynamic favicon generation. * The default value will use OpenSans Regular. */ 'font' => null, /* * Intervention Image supports "GD Library" and "Imagick" to process images * internally. You may choose one of them according to your PHP * configuration. By default, PHP's "GD Library" implementation is used. * * If you want to convert ICO files, you need to use imagick. * * Supported: "gd", "imagick" * */ 'image_driver' => 'gd', /* * The prefix to use for the dynamic favicon URL. */ 'url_prefix' => 'laravel-favicon', /* * The favicon generator class to use. The default generator * makes use of the environment settings defined in this file. * But you can create your own favicon generator if you want. */ 'generator' => \BeyondCode\LaravelFavicon\Generators\EnvironmentGenerator::class, ];
根据您的需求修改设置。
自定义生成器
默认favicon生成器将在favicon的右下角写入文本,使用所需颜色、字体和背景颜色。如果您想生成一个完全自定义的favicon,您可以在配置文件中创建自己的FaviconGenerator实现类并将其设置在其中。
生成器应该实现以下接口
interface FaviconGenerator { public function generate(string $icon): Response; public function shouldGenerateFavicon(): bool; }
generate
方法接收图标url/文件名,并期望您返回一个illuminate HTTP响应。
您可以使用shouldGenerateFavicon
方法来确定是否应生成自定义favicon。
常见问题解答
我的ICO文件不起作用,为什么?
为了修改ICO文件,您需要在config/favicon.php
文件中安装并启用Imagick PHP库。
使用此包会有性能影响吗?
没有 - 默认生成器仅当指定的环境启用时修改您的favicon。这意味着,生产环境只看到您已经拥有的静态资产。
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献。
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件marcel@beyondco.de联系,而不是使用问题跟踪器。
致谢
许可协议
MIT许可协议(MIT)。有关更多信息,请参阅许可文件。