PHP code example of genkgo / favicon

1. Go to this page and download the library: Download genkgo/favicon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

genkgo / favicon example snippets



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);
}