Grabbing website Favicons using curl and php

Google Shared Stuff allows one to easily get the Favicon of any website with a single line. For instance to get the Favicon of we can use the following in a browser.

We can do do the same using PHP and curl using the following code.

This will display the Favicon in the browser. An even more interesting thing we can do is to save the same to a PNG file. A little modification to the above code will yield the following.

Below is a more elaborate code to grab Favicons from a list of urls and combine them into a single image.

= 60) {
        $x = 0;
        $y += 20;

/* Output the newly created image */
header('Content-Type: image/gif');


The above code will create the following image in your browser.

A little more code change and you can save the image to a file.

7 thoughts to “Grabbing website Favicons using curl and php”

  1. Thanks for the code. But i didnt got solved as my code generates url s with http:// prefix so i cant use them with it. Any code to remove http:// ?

  2. Try this simple code-

    $url = “”;

    if(substr($url,0,5) == “http:”)
    $url = substr($url,7,strlen($url)-5);
    echo $url;

  3. First of all, thanks for sharing this. This is exactly what I am looking for.

    I am integrating this on my website but it seems that images saved on local folder is not displaying on IE. Do you have any idea what causing this issue? I don’t have any problem with other browser and all images shows up perfectly it just with IE. I don’t know if the problem is with IE or how the images are saved on local folder because some are actually showing up like facebook.

    Any idea?

    Thanks in advance

  4. @ Juan. I’ve been playing around with the same problem. I had this code working and I think I had the same problem.

    I was under the impression though that the favicon the google service returns has been changed to png. However I do remember having the problem of favicons not showing in IE.

    The reason is that although Microsoft came up with the .ico filetype their browsers don’t support it as an image type, hence it won’t work in IE. I hate Microsoft. (I’ll throw in here that windows 8 is absolute rubbish AVOID!)

    Anyway, I tried to change the format of the .ico file in another project I was working on and gave up because I couldn’t find any useful info and php doesn’t have a function to handle .ico files.

    If you figure something out, post it for others plz!

  5. I’d recommend using instead of google’s S2 favicon service. Google’s service was never meant to be public, and could go away at any time. Grabicon was built to be a drop-in replacement – it’s also free, and it works the same way.

    It also lets you specify what size you want the icon to be, and generates unique default icons for sites that don’t have one. This ensures a uniform user experience for web/mobile apps, because icons are always the requested size, and never missing.


    Icons are 32px by default, but you can specify a custom size:

    Unlike google, grabicon is fully supported and being actively improved. Icon retrieval is very fast.

Leave a Reply

Your email address will not be published.