beyondcode/
laravel-favicon
g4t.io

Laravel Favicon Package

26 views 376 stars by Paul Redmond

Create dynamic favicons based on your environment settings.

README from beyondcode/laravel-favicon Open on GitHub →

Laravel Favicon

Latest Version on Packagist Total Downloads

Create dynamic favicons based on your environment settings.

Laravel Package Development

https://phppackagedevelopment.com

If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course.

Installation

You can install the package via composer:

composer require beyondcode/laravel-favicon

The service provider for this package will be automatically registered for you.

Compatibility

1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
5.6.x ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ❌
5.7.x ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ❌
5.8.x ❌ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ❌
6.x ❌ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ❌
7.x ❌ ❌ ✅ ✅ ✅ ✅ ✅ ✅ ❌
8.x ❌ ❌ ❌ ✅ ✅ ✅ ✅ ✅ ❌
9.x ❌ ❌ ❌ ❌ ❌ ✅ ✅ ✅ ❌
10.x ❌ ❌ ❌ ❌ ❌ ✅ ✅ ✅ ✅
11.x ❌ ❌ ❌ ❌ ❌ ❌ ✅ ✅ ✅
12.x ❌ ❌ ❌ ❌ ❌ ❌ ❌ ✅ ✅
13.x ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ✅

Usage

To make use of this package, make use of the favicon helper function that this package provides.

You can simply wrap the function around your favicon icon names, like this:

<link rel="icon" type="image/png" sizes="32x32" href="{{ favicon(asset('favicon-32x32.png')) }}">

<link rel="shortcut icon" href="{{ favicon('favicon.ico') }}" />

<!-- SVG favicons are also supported! -->
<link rel="icon" type="image/svg+xml" href="{{ favicon(asset('favicon.svg')) }}">

Customization

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.

To modify the default values, publish the package configuration file using:

php artisan vendor:publish --provider='BeyondCode\LaravelFavicon\FaviconServiceProvider' --tag='config'

This will publish the config/favicon.php file.

This is what the default content looks like:

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,


];

Modify the settings to suit your needs.

Custom generator

The default favicon generator will write the text on the bottom-right corner of your favicon, in the desired color, font and background-color. If you want to generate a completely custom favicon, you can create your own FaviconGenerator implementation class and set it in the configuration file.

This is the interface that the generator should implement:

interface FaviconGenerator
{
    public function generate(string $icon): Response;

    public function shouldGenerateFavicon(): bool;
}

The generate method receives the icon url/filename and expects you to return an illuminate HTTP response.

The shouldGenerateFavicon method can be used to determine if a custom favicon should get generated.

FAQ

My ICO files are not working, why?

In order to modify ICO files, you need the Imagick PHP library installed and enabled in your config/favicon.php file.

Is there a performance impact when I'm using this package?

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.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News