PHPackages                             smtws/google-font-downloader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. smtws/google-font-downloader

ActiveLibrary[File &amp; Storage](/categories/file-storage)

smtws/google-font-downloader
============================

php google fonts downloader with local css creation

1.0.0(6y ago)3134MITPHPPHP ^7.1CI passing

Since Jan 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/smtws/gFontDownloader)[ Packagist](https://packagist.org/packages/smtws/google-font-downloader)[ RSS](/packages/smtws-google-font-downloader/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

gFontDownloader
===============

[](#gfontdownloader)

[![Latest Stable Version](https://camo.githubusercontent.com/81b9d315465cc159a827f85fa6de2073581369d4fe1b196c5d0e866491f7712d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d7477732f676f6f676c652d666f6e742d646f776e6c6f616465722e737667)](https://packagist.org/packages/smtws/google-font-downloader)[![Total Downloads](https://camo.githubusercontent.com/d28b9a8ff714cf6423a89c24a4670d4bd6e261ddbbda66d1664c7424f174b9b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d7477732f676f6f676c652d666f6e742d646f776e6c6f616465722e737667)](https://packagist.org/packages/smtws/google-font-downloader)

gFontDownloader is a PHP tool that allows you to download Google Fonts and create local CSS files for them.

Features
--------

[](#features)

- Download Google Fonts to a local directory
- Create local CSS files for the downloaded fonts
- PSR-3 compatible logging

Configuration
-------------

[](#configuration)

You can configure gFontDownloader using one of the following methods:

1. Set configuration in `config.json` and call `->setConfig()`
2. Set configuration via `->setConfig([array of configuration key-value pairs])`
3. Set configuration via `->setConfig($key, $value)`

Combinations of these methods are possible.

### Configuration Options

[](#configuration-options)

- `output`: Directory where fonts are downloaded to (each font family will have its own subdirectory). Defaults to `./`
- `formats`: Optional array of font formats to be downloaded. Defaults to all valid values. Valid values are: `eot`, `woff`, `woff2`, `svg`, `ttf`
- `onRecoverableError`: How to handle recoverable errors. Valid values are: `stop` (default), `recover`

Adding Fonts to Download List
-----------------------------

[](#adding-fonts-to-download-list)

You can add fonts to the download list using one of the following methods:

- `->addFont(string $fontFamily, string $fontStyle, array $fontWeights)`

or

- `->addFontByUrl(string $urlOfFont)`

Examples:

- `"https://fonts.google.com/?selection.family=Gelasio:500i,700|Open+Sans|Roboto"`
- `"https://fonts.googleapis.com/css?family=Gelasio:500i,700|Open+Sans|Roboto&display=swap"`

Running the Downloader
----------------------

[](#running-the-downloader)

To start the download process, call `->download()`. This method:

- Returns an array of all downloaded fonts
- Accepts a callback function that is passed information on each font individually

Error Handling
--------------

[](#error-handling)

In case of unrecoverable errors, you can run `->createFamilyCssFiles()` to create Font Family CSS files for fonts that were successfully downloaded before the error occurred (see `example.php`).

Logging
-------

[](#logging)

You can use PSR-3 compatible loggers with gFontDownloader:

```
->setLogger(new \PSRCompatibleLogger());
```

Example Usage
-------------

[](#example-usage)

Here is an example of how to use gFontDownloader:

```
