Favicon dynamics of unread count in PHP_PHP Tutorial

WBOY
Release: 2016-07-14 10:07:11
Original
918 people have browsed it

In Gmail Just launched a small, but really useful feature in Gmail Labs. A dynamic favicon displays the number of unread emails directly on your browser tab icon. If you have lots of browser windows and lots of open tabs at all times, this could be a really fantastic feature to let the user know about any unread items.

Here is a small but powerful script in PHP that allows you to create your own dynamic favicon. We will use PHP's GD library to manipulate the favicon image and add text to it.

Below is a simple script that reads an icon image and adds some text characters.

File: favicon.php


//Read favicon favicon.png template
//File from current directory
$im = imagecreatefrompng("favicon.png");
//$im = imagecreatefromjpg("favicon.jpg"); //Use this function to load a JPEG type favicon
//$im = imagecreatefrombmp("favicon.bmp"); //Use this function to load BMP type favicon


/* The characters to be read need to be added to the favicon
* get request
*/
if(isset($_GET['char']) && !empty($_GET['char'])) {
$string = $_GET['char'];
} else {
/* If no characters are specified, add some default values ​​*/
$string = 'V';
}

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

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

/* Write favicon character
* arguments: image, font size, x coordinate,
* Y coordinate, characterstring, color
*/
imagechar($im, 2, 5, 1, $string, $black);

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

imagepng($im);

?>
The code above is almost self-explanatory. We request from GET and add the favicon image to a character. Note that here, we use a template favicon image,
I modify. You can place any favicon of your choice near the favicon.php file.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477885.htmlTechArticleIn Gmail A small, but really useful feature has just been launched in Gmail Labs. A dynamic favicon displays the number of unread emails directly on your browser tab icon. If your browser window...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template