Favicon Notification Count Dynamic unread

Gmail, Facebook, Twitter has just launched a small but really useful feature. Dynamic Favicon showing unread notifications, messages, or other request counts directly in your browser tab icon. If your browser window has lots and much of tabs open at any time, this could be really an exquisite feature that lets users know of any unread item. Here may be a small and powerful script in PHP that allows you to create your own Dynamic favicon. we'll use the PHP GD library to control the favicon image and add text into it. Below is that the simple script that reads a favicon image adds some text character thereon. File: favicon.php


by : @araratmartiross - coding

<?php

//Read the favicon template from favicon.png
//file from current directory
$im = imagecreatefrompng("favicon.png");
//$im = imagecreatefromjpg("favicon.jpg");   //using this function to load favicon of jpeg type
//$im = imagecreatefrombmp("favicon.bmp"); //using this function to load favicon of bmp type


/* Read the character which needs to be added in favicon from
 * get request
 */
if(isset($_GET['char']) && !empty($_GET['char'])) {
    $string = $_GET['char'];
} else {
    /* If no character is specified; add some default value */
    $string = 'V';
}

/* background color for the favicon */
$bg = imagecolorallocate($im, 255, 255, 255);

/* foreground (font) color for the favicon */
$black = imagecolorallocate($im, 0, 0, 0);

/* Write the character in favicon
 * arguements: image, fontsize, x-coordinate,
 *                y-coordinate, characterstring, color
 */
imagechar($im, 2, 5, 1, $string, $black);

header('Content-type: image/png');

imagepng($im);

?>

2020-05-14 18:19:43