favicon
0.3.4
Requires PHP 8.1+ and both the imagick and DOM extension.
composer require genkgo/favicon
use GenkgoFavicon;
$outputDirectory = '/var/www/html/favicon';
$input = FaviconInput::fromFile('/var/www/html/logo.png', InputImageType::PNG);
// or add a different background color
$input = FaviconInput::fromFile('/var/www/html/logo.png', InputImageType::PNG, '#FF0000');
// or use a svg as input
$input = FaviconInput::fromFile('/var/www/html/logo.svg', InputImageType::SVG);
// or create a letter avatar
$input = FaviconInput::digit('G', '#FFFFFF', '#00AAAD');
$generator = FaviconFullPackageGenerator::newGenerator();
$manifest = new FaviconWebApplicationManifest(
FaviconWebApplicationManifestDisplay::Standalone,
'Title of website',
'Short name of website',
'#00AAAD', // theme color
'#00AAAD', // tile color
);
foreach ($generator->package($input, $manifest, '/') as $fileName => $contents) {
$pathName = $outputDirectory . '/' . $fileName;
file_put_contents($pathName, $contents);
}
// append the head tags to your document
$document = new DOMDocument('1.0', 'UTF-8');
$html = $document->createElement('html');
$document->appendChild($html);
$head = $document->createElement('head');
foreach ($generator->headTags($document, $manifest, '/') as $tag) {
$head->appendChild($tag);
}
// or just generate the tag strings
$tags = [];
$document = new DOMDocument('1.0', 'UTF-8');
foreach ($generator->headTags($document, $manifest, '/') as $tag) {
$tags[] = $document->saveHTML($tag);
}
or use the command-line.
./vendor/bin/favicon-generator --help
./vendor/bin/favicon-generator 'Title of the website' file:public/logo.png output
./vendor/bin/favicon-generator 'Title of the website' file:public/logo.png output --theme-color=#00AAAD --icon-background=#00AAAD --root=/
./vendor/bin/favicon-generator 'Title of the website' letter:G output
./vendor/bin/favicon-generator 'Title of the website' letter:G output --letter-color=#FFFFFF --theme-color=#00AAAD --icon-background=#00AAAD --root=/
There are no tests. Maybe later.