Programmatically Obtain Shortcut Icons
For a side project, I just needed to download the favicons of brands to visually augment a web portal :)
Historically, that icon was named
favicon.ico, and stored in the root directory of the website.
However, nowadays the icon is typically called shortcut icon, and there are tons of options on how to get it into the browers’ tab pane…
Very rarely it’s still named
It’s often not even an ICO file, but a PNG image or an SVG graph.
And developers often refer to it from within a webpage’s HTML code using a
<link ...> tag.
However, it’s pretty convinient to create a link to a brand as it properly resembles the brand’s official log!
Of course, downloading the remote web page, parsing the HTML code, and selecting the correct short cut icon (if any, otherwise falling back to
$domain/favicon.ico including error handling etc) would be pretty expensive and error-prone.
In such cases it’s always good to outsource the job to someone who’s doing that anyway for their business..
And lucky us *hrumph* there is Google! ;-)
Google Shares Stuff
Google provides a Shared Stuff (s2) link to automatically retrieve the favicon image of any website. The syntax is:
Thus, the GET parameter
domain carries the domain of the site of interest (here it’s
Pretty straight forward, isn’t it?
As a bonus, you’ll get a small PHP function to download the icon and store it on your disk:
This will retrieve the favicon for
$url, store it in
CACHE_DIR, and return the path to the stored file (the file name being the sha1 hash of the domain).
Just make sure you defined
CACHE_DIR and enjoy your icons :)
So I heard you don’t like Google?
There is at least one alternative:
There is also PHP tool for that, if you want to self-host such a tool:
- software (155) ,
- web (82) ,
- website (21) ,
- media (54) ,
- html (7) ,
- shortcut (9) ,
- howto (25) ,
- php (15)
- google (13) ,
- media (60) ,
- network (78) ,
- php (8) ,
- remote (22) ,
- snippet (13) ,
- trick (60) ,
- web (5)