PHP code example of smtws / google-font-downloader

1. Go to this page and download the library: Download smtws/google-font-downloader 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/ */

    

smtws / google-font-downloader example snippets


->setLogger(new \PSRCompatibleLogger());



mtws\gFontDownloader;

// Create a new instance of the downloader
$downloader = new gFontDownloader();

// Set configuration
$downloader->setConfig([
    'output' => 'fonts/',
    'formats' => ['woff2', 'ttf'],
    'onRecoverableError' => 'recover'
]);

// Add fonts to the download list
$downloader->addFont('Gelasio', 'italic', [500, 700]);
$downloader->addFontByUrl('https://fonts.googleapis.com/css?family=Open+Sans|Roboto&display=swap');

// Set a logger (optional)
$downloader->setLogger(new \MyLogger());

// Run the downloader
$downloadedFonts = $downloader->download();

// Handle downloaded fonts
foreach ($downloadedFonts as $font) {
    echo "Downloaded font: " . $font['family'] . "\n";
}