arthurhoaro / favicon
PHP Library used to discover favicon from given URL
Installs: 454 286
Dependents: 0
Suggesters: 0
Security: 0
Stars: 32
Watchers: 4
Forks: 11
Open Issues: 3
Requires
- php: ^8.0
- ext-dom: *
- ext-fileinfo: *
Requires (Dev)
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.5
- weew/helpers-filesystem: ~1.0
This package is auto-updated.
Last update: 2024-10-23 15:47:35 UTC
README
This library is based on Chris Shiflett work.
Here are the changes you can see in this version:
- Cover more use case to find favicons
- Composer support
- Various technical changes and improvements
- Unit tests
Requirements
- PHP 8.0+ (you can use v1.x for PHP 5.6+)
- php-xml extension: parse HTML content
- php-fileinfo extension: check image type
Composer
Use Composer by adding the following lines in your composer.json
:
"require": {
"arthurhoaro/favicon": "~2.0"
}
Basic Usage
require_once('vendor/autoload.php'); $favicon = new \Favicon\Favicon(); echo $favicon->get('http://hoa.ro'); // Displays: http://hoa.ro/themes/hoaro/img/favicon.png var_dump($favicon->get('http://nofavicon.tld', FaviconDLType::HOTLINK_URL)); // Returns false
You can avoid hotlinking by downloading the favicons:
$favicon = new \Favicon\Favicon(); // return the generated filename inside the cache folder $favicon->get('http://hoa.ro', FaviconDLType::DL_FILE_PATH); // return false $favicon->get('http://nofavicon.tld');
Or directly get the raw image as a binary string:
$favicon = new \Favicon\Favicon(); // return the binary string of the downloaded favicon $favicon->get('http://hoa.ro', FaviconDLType::RAW_IMAGE); // return false $favicon->get('http://nofavicon.tld');
Note:
DL_FILE_PATH
andRAW_IMAGE
require the cache to be enabled.
Configure
You can setup cache settings:
$favicon = new Favicon(); $settings = array( // Cache directory 'dir' => '/tmp/', // Cache timeout in seconds 'timeout' => 86400, // Default image when no favicon is found 'defaultico' => 'img/fav.ico' ); $favicon->cache($settings);