adamb/google-fonts

Get a list of Google Fonts and search by type or weight

1.0.1 2020-10-08 10:51 UTC

This package is auto-updated.

Last update: 2024-12-23 00:11:00 UTC


README

Build Status Scrutinizer Quality Score Minimum PHP Version

Google Fonts Lists PHP

Produces a PHP array of all of the fonts available in Google Fonts searchable by weight/subset/type;

Installation

Installation is available via Composer/Packagist:

composer require adamb/google-fonts

You will also need to obtain a Google Fonts API key to use this package.

Usage

Example of usage can be found below:

Set-up

<?php
require "vendor\autoload.php";

use Fonts\GoogleFonts;

$googleAPIKey = 'my-api-key';

$fonts = new GoogleFonts($googleAPIKey);

List Fonts

You can list fonts using 3 different methods (getFontsByWeight($weight), getFontsBySubset($subset) and getFontsByType($type).

Example Usage

// Lists the fonts with a weight of 300
$fonts->getFontsByWeight(300); // Returns array

// Lists the fonts with a weight of 500 and italic
$fonts->getFontsByWeight('500italic'); // Returns array

// Lists all of the fonts with the latin subset
$fonts->getFontsBySubset('latin'); // Returns array

// Lists all of the serif fonts
$fonts->getFontsByType('serif'); // Returns array

// Lists all of the handwriting fonts
$fonts->getFontsByType('handwriting'); // Returns array

List Types Available

You can list the available options using 1 of 3 different methods (getFontWeights(), getFontSubsets() or getFontTypes())

Font Weights

PHP
$weights = $fonts->getFontWeights();
print_r($weights);
HTML Output
Array ( [0] => 100 [1] => 100italic [2] => 200 [3] => 200italic [4] => 300italic [5] => italic [6] => regular [7] => 300 [8] => 500 [9] => 500italic [10] => 600 [11] => 600italic [12] => 700 [13] => 700italic [14] => 800 [15] => 800italic [16] => 900 [17] => 900italic ) 

Font Subsets

PHP
$subsets = $fonts->getFontSubsets();
print_r($subsets);
HTML Output
Array ( [0] => arabic [1] => bengali [2] => cyrillic [3] => cyrillic-ext [4] => devanagari [5] => greek [6] => greek-ext [7] => gujarati [8] => gurmukhi [9] => hebrew [10] => kannada [11] => khmer [12] => korean [13] => latin [14] => latin-ext [15] => malayalam [16] => myanmar [17] => oriya [18] => sinhala [19] => tamil [20] => telugu [21] => thai [22] => vietnamese )

Font Types/Categories

PHP
$types = $fonts->getFontTypes();
print_r($types);
HTML Output
Array ( [0] => display [1] => handwriting [2] => monospace [3] => sans-serif [4] => serif ) 

License

This software is distributed under the MIT license. Please read LICENSE for information on the software availability and distribution.