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.php” file for creating the image:
- $img = imagecreatefrompng(“icon.png”);
- if(isset($_GET[‘char’emptyempty($_GET[‘char’])) {
- $string = $_GET[‘char’];
- } else {
- $string = ‘V’;
- }
- $bg = imagecolorallocate($img, 255, 255, 255);
- $black = imagecolorallocate($img, 0, 0, 0);
- imagechar($img, 2, 5, 1, $string, $black);
- header(‘Content-type: image/png’);
- imagepng($img);
- ?>
This is a “favicon.php” file for creating a dynamic Favicon icon in the PHP website.
-
Dynamic favicon in PHP! - “shortcut icon” href=“icon.php?char=“ />
- body, input{
- font-family: Calibri, Arial;
- margin:0px;
- font-size: 19px;
- }
- h1 {
- margin: 0 0 0 20px;
- }
- html, body, #container { height: 100%; }
- body > #container { height: auto; min-height: 100%; }
- #header {
- height:50px;
- background-color:#ddd;
- border-bottom:1px solid #aaa;
- width:100%;
- font-size: 15px;
- }
- #footer {
- font-size: 12px;
- clear: both;
- position: relative;
- z-index: 10;
- height: 3em;
- margin-top: -3em;
- text-align:center;
- }
- .demo {
- width:150px;
- height:150px;
- padding:5px;
- background-color:#ff8811;
- position:absolute;
- top:150px;
- left:300px;
- }
- #content { padding-bottom: 3em; margin: 20px;}
- “container”>“header”>
Dynamic favicon in PHP
“content”>“http://www.c-sharpcorner.com”
>Click here to view this ArticleEnter any character in the following textbox and Generate favicon
>- “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:
You will see your Favicon in your tab.
Article Prepared by Ollala Corp