Favicon dynamic of unread count in PHP

Source: Internet
Author: User
Tags php file

  in Gmail just launched a small but really useful feature in Gmail Labs. The number of unread emails is displayed directly in the dynamic favicon of your browser tab icon. If your browser window lots and lots are open at any time, this may really be a fantastic feature that lets users know about any unread items.

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

The following is a simple script that reads an icon image to add some text characters.

File: favicon.php

<?php

//Read favicon favicon.png templates
//files from the current directory
$im = imagecreatefrompng ("Favicon.png");
//$im = Imagecreatefromjpg ("favicon.jpg"); Use this function to load the Favicon
//$im = Imagecreatefrombmp ("Favicon.bmp") of the JPEG type;////Use this function to load a BMP type of Favicon


/* Read characters , you need to add a
* GET request
*/
if (isset ($_get[' char ']) &&!empty ($_get[' char ']) in Favicon {
$string = $_get[' Char '];
} else {
/* If no characters are specified to add some default values */
$string = ' V ';
}

/* favicon background color */
$BG = imagecolorallocate ($im, 255, 255, 255);

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

/* Write Favicon characters
* arguements: Images, font size, x coordinates,
* y coordinates, characterstring, color
*/
Imagechar ($im, 2, 5, 1, $string, $b lack);

Header (' content-type:image/png ');

Imagepng ($im);


The code above is almost self-explanatory. We add the favicon image to a character from Get request. Note that here we use a template for the favicon image,
I modify. You can select any favicon near your favicon.php file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.