<?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);
?>
Code language: PHP (php)
The above code is pretty much self explanatory. We read a character from GET request and add it into the favicon image. Note here that we are using a template favicon image which me modify. You can place any favicon of your choice near favicon.php file. Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
We can make some favicon_1.png favicon_2.png ... favicon_9.png
and use javascript to set it.
You can then use a link tag to set the png as your favicon like this:
thanksssss..... help full ....for me......
why do you definde $bg and don't use it anywhere?
Hey You are really great, You show a really great method to use counter favicon.
Thanks Viral. Very useful for me!!
I improved it a little bit, hope you are fine with this: https://github.com/gaffling/PHP-dynamic-Counter-Favicon