Create Favicon in PHP – Info PHP

Introduction

 

In this article I will explain Favicons in PHP. In this article I will use a small and powerful script for creating Dynamic Favicons and use the PHP GD library to manipulate the Favicon image and add text into it. Use the GD library to create the image. You can download GD library and include it in the WWW folder. After including the GD library you can run PHP info() to check that GD Support is enabled.

 

Example

 

This is the “icon.” file for creating the image:

  1. $img = imagecreatefrompng(“icon.png”);  
  2.   
  3. if(isset($_GET[‘char’]) && !emptyempty($_GET[‘char’])) {  
  4.        $string = $_GET[‘char’];  
  5. else {  
  6.        $string = ‘V’;  
  7. }  
  8. $bg = imagecolorallocate($img, 255, 255, 255);  
  9. $black = imagecolorallocate($img, 0, 0, 0);  
  10. imagechar($img, 2, 5, 1, $string$black);  
  11. header(‘Content-type: image/png’);  
  12. imagepng($img);  
  13. ?>  

This is a “favicon.php” file for creating a dynamic Favicon icon in the PHP website.

  1.   
  2.   
  3.        Dynamic favicon in PHP!  
  4.        “shortcut icon” href=“icon.php?char= />  
  5.   
  6.   
  7.   
  8. “container”>  
  9. “header”>  
  10.        

    Dynamic favicon in PHP

      

  

  • “content”>  
  •        

    “http://www.c-sharpcorner.com”>Click here to view this Article

      

  •        

    Enter any character in the following textbox and Generate favicon

      

  •        “post”>  
  •                 
  •               “text” name=“char” style=“width:40px” maxlength=“1”/>  
  •               
      
  •               “submit” value=“Generate favicon” />  
  •        

      

  •        Dynamic Favicon  
  •        “icon.php?char= border=“0”/>  
  •        
      
  •   

  •   

  •   
  •   
  • Output

     

     

    This image is already set with a Favicon as “V” and I want to use “R” for the new Favicon. Such as shown in the following image:

     

    image2.jpg

     

    You will see your Favicon in your tab.

     

    image3.jpg

    Article Prepared by Ollala Corp

    You might also like More from author

    Leave A Reply

    Your email address will not be published.