Laravel Favicon - Create dynamic favicons based on your environment settings.

Overview

Laravel Favicon

Latest Version on Packagist Build Status Quality Score 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.

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') }}" />

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:

'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, ]; ">
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 [email protected] instead of using the issue tracker.

Credits

License

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

Comments
  • Installation failed, reverting ./composer.json to its original content.

    Installation failed, reverting ./composer.json to its original content.

    This is the output

    Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for beyondcode/laravel-favicon ^1.0 -> satisfiable by beyondcode/laravel-favicon[1.0.0]. - Conclusion: remove laravel/framework v5.8.26 - Conclusion: don't install laravel/framework v5.8.26 - beyondcode/laravel-favicon 1.0.0 requires illuminate/support 5.6.|5.7. -> satisfiable by illuminate/support[5.6.x-dev, 5.7.17, 5.7.18, 5.7.19, 5.7.x-dev, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.25, v5.6.26, v5.6.27, v5.6.28, v5.6.29, v5.6.3, v5.6.30, v5.6.31, v5.6.32, v5.6.33, v5.6.34, v5.6.35, v5.6.36, v5.6.37, v5.6.38, v5.6.39, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9, v5.7.0, v5.7.1, v5.7.10, v5.7.11, v5.7.15, v5.7.2, v5.7.20, v5.7.21, v5.7.22, v5.7.23, v5.7.26, v5.7.27, v5.7.28, v5.7.3, v5.7.4, v5.7.5, v5.7.6, v5.7.7, v5.7.8, v5.7.9]. - don't install illuminate/support 5.6.x-dev|don't install laravel/framework v5.8.26 - don't install illuminate/support 5.7.17|don't install laravel/framework v5.8.26 - don't install illuminate/support 5.7.18|don't install laravel/framework v5.8.26 - don't install illuminate/support 5.7.19|don't install laravel/framework v5.8.26 - don't install illuminate/support 5.7.x-dev|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.0|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.1|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.10|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.11|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.12|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.13|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.14|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.15|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.16|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.17|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.19|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.2|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.20|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.21|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.22|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.23|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.24|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.25|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.26|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.27|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.28|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.29|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.3|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.30|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.31|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.32|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.33|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.34|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.35|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.36|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.37|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.38|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.39|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.4|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.5|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.6|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.7|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.8|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.6.9|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.0|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.1|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.10|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.11|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.15|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.2|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.20|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.21|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.22|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.23|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.26|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.27|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.28|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.3|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.4|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.5|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.6|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.7|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.8|don't install laravel/framework v5.8.26 - don't install illuminate/support v5.7.9|don't install laravel/framework v5.8.26 - Installation request for laravel/framework (locked at v5.8.26, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.26]. Installation failed, reverting ./composer.json to its original content.

    opened by aleedhillon 2
  • Make it a dev dependency

    Make it a dev dependency

    Very nice little quality of life feature.

    But I only need this dependency in my development and test environments, so it qualifies as a dev dependency. So the first thing I did was add a custom helper method for the production environment.

    /**
     * Placeholder for the laravel-favicon package that doesn't exist on production
     */
    if ( ! function_exists('favicon') && env('APP_ENV') == 'production') {
        function favicon($image)
        {
            return $image;
        }
    }
    

    I'm sure you already thought about this, but I'd like to propose adding this option to the readme. What do you think?

    opened by winkbrace 2
  • Fix for favicon route when app not in web root

    Fix for favicon route when app not in web root

    Hi, I encountered a problem running favicon when the site is not in webroot (ex: http://localhost/mysite/public) -> generated favicon path was pointing outside the site root.

    opened by abejenaru 1
  • Add laravel 7 support

    Add laravel 7 support

    hi, this solve #11 issue. I added Laravel 7 support.

    All tests passed.

    > vendor/bin/phpunit
    PHPUnit 8.5.4 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 7.3.12 with Xdebug 2.8.1
    Configuration: /Users/koala/Github/laravel-favicon/phpunit.xml.dist
    .....                                                               5 / 5 (100%)
    
    Time: 2.11 seconds, Memory: 16.00 MB
    
    OK (5 tests, 8 assertions)
    
    Generating code coverage report in Clover XML format ... done [15 ms]
    
    Generating code coverage report in HTML format ... done [21 ms]
    
    opened by danielebarbaro 1
  • Add support for Laravel 5.8.* and 6.* and PHP 7.3

    Add support for Laravel 5.8.* and 6.* and PHP 7.3

    I added the version numbers for 5.8.* and 6.* and modified the travis.yml file so that all possible combinations of PHP versions and Laravel are tested.

    That would also fix #4.

    opened by gerpo 1
  • Support Laravel 9

    Support Laravel 9

    If i try to install this package in a l9 project composer fail to install

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Root composer.json requires beyondcode/laravel-favicon ^1.4 -> satisfiable by beyondcode/laravel-favicon[1.4.0].
        - beyondcode/laravel-favicon 1.4.0 requires illuminate/http 5.6.*|5.7.*|5.8.*|6.*|7.*|8.* -> found illuminate/http[v5.6.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
    
    You can also try re-running composer require with an explicit version constraint, e.g. "composer require beyondcode/laravel-favicon:*" to figure out if any version is installable, or "composer require beyondcode/laravel-favicon:^2.1" if you know which you need.
    
    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
    
    opened by Wit3 1
  • Support for PHP 8.0

    Support for PHP 8.0

    Is this in the works?

    We have a project where we use PHP 8.0 and would love to use this package to distinguish between production and development tabs in the browser.

    opened by mwkcoding 1
Releases(1.4.0)
Owner
Beyond Code
Beyond Code
Create images with embedded text using advanced typography

Image with Text This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block's ali

New Media Campaigns 144 Sep 7, 2022
Create material deisgn avatars for users just like Google Messager. It may not be unique but looks better than Identicon or Gravatar.

Material-Design-Avatars Create material deisgn avatars for users just like Google Messager. It may not be unique but looks better than Identicon or Gr

Canbin Lin 268 Sep 14, 2022
Wonderfully easy on-demand image manipulation library with an HTTP based API.

Glide Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud i

The League of Extraordinary Packages 2.4k Dec 19, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Clément Guillemain 853 Dec 27, 2022
Another web based photo gallery

Phyxo Simply share your images. Requirements This project use severals librairies that need at least PHP 7.3.0 This project uses a database and suppor

Nicolas 16 Oct 13, 2022
php-gd based image templates

gdaisy A highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers. Installation 1. Require erikahe

Erika Heidi 67 Nov 22, 2022
PHP Library for generating SVG avatars based on React Avataaars

PHP library for Avataaars PHP Library for generating SVG avatars based on React Avataaars.

null 5 Apr 16, 2022
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.

Lychee A great looking and easy-to-use photo-management-system. Since the 1st of April 2018 this project has moved to it's own Organisation (https://g

Tobias Reich 6.2k Dec 31, 2022
👤 Add your own default WordPress avatar.

Custom User Avatar WordPress currently only allows you to use custom avatars that are uploaded through Gravatar. Custom User Avatar enables you to use

David Artiss 13 Jan 24, 2022
⚡ Dynamically generated, customizable SVG that gives the appearance of typing and deleting text. Typing SVGs can be used as a bio on your Github profile readme or repository.

⚡ Dynamically generated, customizable SVG that gives the appearance of typing and deleting text. Typing SVGs can be used as a bio on your Github profile readme or repository.

Jonah Lawrence 2k Jan 9, 2023
A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.

Lychee Organisation 2.3k Jan 1, 2023
Manage your photos with Piwigo, a full featured open source photo gallery application for the web

Manage your photos with Piwigo, a full featured open source photo gallery application for the web. Star us on Github! More than 200 plugins and themes available. Join us and contribute!

Piwigo 1.8k Apr 14, 2022
This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.

Laravel FFMpeg This package provides an integration with FFmpeg for Laravel 6.0 and higher. Laravel's Filesystem handles the storage of the files. Fea

Protone Media 1.3k Jan 7, 2023
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS

Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS that gives to the users the ability to create or edit their own profiles (including profile image and description), upload images and share them among friends

null 0 Jul 24, 2021
Laravel Qcloud Content Security T-Sec 腾讯云内容安全(文字图片内容审核)服务

Laravel Qcloud Content Security T-Sec 天御内容安全服务使用了深度学习技术,识别文本/图片中出现的可能令人反感、不安全或不适宜内容,支持用户配置词库/图片黑名单,识别自定义的识别类型。

安正超 34 Jun 20, 2022
An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

Thomas 56 Dec 16, 2022