📜 ⬆️ ⬇️

Conversion favicon domain to png service (with source code :)

Recently, I wrote about looking for ways to get domain icons in a normal format (ie, png) and about wanting to write my own separate service for this, since public converters from Google and Yandex have significant drawbacks.

And now he is ready.

It works as a separate site - upon request it receives icons for new domains, periodically updates them and gives them to everyone. If the desired icon is not yet available, the standard favicon update script for the domain is given. After the update, the domain icon will be available (if it has one).
The script looks at the meta tags of the page in search of a link to favicon. If not found - goes to domain.com/favicon.ico . If somewhere the icon is found, it determines its type and converts it into png.

You can test all this at http://favicons.tools.strangecompany.ru/?domain=domain.com . This host will live for a long time, since we already use it in our projects. You can use and you. And if you want - just download the code from svn:
')
  svn co http://svn.pub.strangecompany.ru/domain_favicon/trunk


For those who want to use the library in their project, the opportunity to easily change the behavior is available, injecting dependencies into the Favicon class:
1. Class for receiving web pages - in case some mechanism is used. To do this, you need to write a class that implements the IFaviconWebFetcher interface and pass it to the Favicon constructor.

2. A class for getting an icon from a webpage. In case you implement a more efficient solution, you need to create a class that implements the IFaviconExtractor interface and, again, pass it to the Favicon constructor.

3. Class for turning the image into png. Maybe you are using PHP 5.3 and want to work with ICO inline functions. Or write your own, more efficient class - you just need to implement the IFaviconConverter interface and, of course, pass it on to the Favicon constructor.

Bugs, comments, suggestions - in the tracker . Flowers, girls and sweets - by mail;)

Source: https://habr.com/ru/post/49570/


All Articles