vortech-studio/laravel-favicon

根据您的环境设置创建动态favicon。

1.5.0 2023-12-12 18:18 UTC

This package is not auto-updated.

Last update: 2024-10-02 20:49:21 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

根据您的环境设置创建动态favicon。

Laravel包开发

https://phppackagedevelopment.com

如果您想学习如何自己创建可重用的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') }}" />

自定义

您可以根据需要完全自定义要启用的环境以及要使用的字体和颜色。

要修改默认值,使用以下命令发布包配置文件

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。这意味着,生产环境只会看到您已经拥有的静态资源。

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何安全问题,请通过电子邮件marcel@beyondco.de联系,而不是使用问题跟踪器。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件