PHP favicon dynamic _ PHP Tutorial

Source: Internet
Author: User
The favicon in PHP is dynamic. Just launched in Gmail, but really useful features are available in Gmail Lab. The number of unread emails is displayed directly on the dynamic favicon in your browser tab. If your browser window is small but actually useful in Gmail Lab. The number of unread emails is displayed directly on the dynamic favicon in your browser tab. If your browser opens a tag for the location and location at any time, it may be a wonderful feature to let users know about any unread projects.

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

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

File: favicon. php


// Read the favicon favicon.png Template
// File from the current directory
$ Im = imagecreatefrompng ("favicon.png ");
// $ Im = imagecreatefromjpg ("favicon.jpg"); // use this function to load the favicon of the JPEG type
// $ Im = imagecreatefrombmp ("favicon.bmp"); // use this function to load favicon of the BMP type


/* Read characters, which must be added to favicon
* Get request
*/
If (isset ($ _ GET ['char ']) &! Empty ($ _ GET ['char ']) {
$ String = $ _ GET ['char '];
} Else {
/* Add some default values if no character is specified */
$ String = 'V ';
}

/* Background color of 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 above code is almost self-evident. We add the favicon image to a character from the GET request. Note: Here we use the favicon image of a template,
I modified. You can select any favicon from the favicon. php file near you.

Middleware has just launched a small but really useful feature in the Gmail Lab. The number of unread emails is displayed directly on the dynamic favicon in your browser tab. If your browser window...

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.