favicon
0.3.4
Erfordert PHP 8.1+ und sowohl die imagick- als auch die DOM-Erweiterung.
composer require genkgo/favicon
use Genkgo Favicon ;
$ outputDirectory = ' /var/www/html/favicon ' ;
$ input = Favicon Input :: fromFile ( ' /var/www/html/logo.png ' , InputImageType :: PNG );
// or add a different background color
$ input = Favicon Input :: fromFile ( ' /var/www/html/logo.png ' , InputImageType :: PNG , ' #FF0000 ' );
// or use a svg as input
$ input = Favicon Input :: fromFile ( ' /var/www/html/logo.svg ' , InputImageType :: SVG );
// or create a letter avatar
$ input = Favicon Input :: digit ( ' G ' , ' #FFFFFF ' , ' #00AAAD ' );
$ generator = Favicon FullPackageGenerator :: newGenerator ();
$ manifest = new Favicon WebApplicationManifest (
Favicon WebApplicationManifestDisplay :: 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 );
}
oder verwenden Sie die Befehlszeile.
./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=/
Es gibt keine Tests. Vielleicht später.