Favicon Dynamic _php tutorial for unread counts in PHP

Source: Internet
Author: User
In Gmail just launched the small but really useful feature in Gmail Labs. The number of unread e-mails is displayed directly in the Favicon of your browser tab icon. If your browser window lots and lots are always open to the label, this may really be a fantastic feature to let users know any unread items.

Here is a small and 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.

Here is a simple script to read an icon image to add some text characters.

Files: favicon.php


Read the template of the Favicon favicon.png
Files from the current directory
$im = Imagecreatefrompng ("Favicon.png");
$im = imagecreatefromjpg ("favicon.jpg"); Use this function to load the favicon of a JPEG type
$im = Imagecreatefrombmp ("Favicon.bmp"); Use this function to load a BMP type of Favicon


/* Read characters that need to be added in 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 ';
}

/* 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 characters
* arguements: 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 of the favicon image,
I modified. You can select any favicon near your favicon.php file.

http://www.bkjia.com/PHPjc/371846.html www.bkjia.com true http://www.bkjia.com/PHPjc/371846.html techarticle in Gmail just launched the small but really useful feature in Gmail Labs. The number of unread e-mails is displayed directly in the Favicon of your browser tab icon. If your browser window ...

  • Related Article

    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.