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 the image. You can download GD library and include it in the WWW folder. After including the GD library you can run PHP () to check that GD Support is enabled.

 

Example

 

This is the “icon.php” 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. body, input{  
  6.        font-family: Calibri, Arial;  
  7.        margin:0px;  
  8.        font-size: 19px;  
  9. }  
  10. h1 {  
  11.        margin: 0 0 0 20px;  
  12. }  
  13. html, body, #container { height: 100%; }  
  14. body > #container { height: auto; min-height: 100%; }  
  15.    
  16. #header {  
  17.        height:50px;  
  18.        background-color:#ddd;  
  19.        border-bottom:1px solid #aaa;  
  20.        width:100%;  
  21.        font-size: 15px;  
  22. }  
  23. #footer {  
  24.        font-size: 12px;  
  25.        clear: both;  
  26.        position: relative;  
  27.        z-index: 10;  
  28.        height: 3em;  
  29.        margin-top: -3em;  
  30.        text-align:center;  
  31. }  
  32. .demo {  
  33.        width:150px;  
  34.        height:150px;  
  35.        padding:5px;  
  36.        background-color:#ff8811;  
  37.        position:absolute;  
  38.        top:150px;  
  39.        left:300px;  
  40. }  
  41. #content { padding-bottom: 3em; margin: 20px;}  
  42.   
  43.   
  44.   
  45. “container”>  

  46. “header”>  

  47.        

    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
    Leave A Reply

    Your email address will not be published.