adamb/google-fonts

获取Google Fonts列表,可按类型或粗细度搜索

1.0.1 2020-10-08 10:51 UTC

This package is auto-updated.

Last update: 2024-09-22 23:30:28 UTC


README

Build Status Scrutinizer Quality Score Minimum PHP Version

Google Fonts列表PHP

生成一个PHP数组,包含Google Fonts中所有可搜索的字体,可按粗细度/子集/类型进行搜索;

安装

安装可通过Composer/Packagist进行。

composer require adamb/google-fonts

您还需要获取一个Google Fonts API密钥来使用此包。

使用

以下为使用示例

设置

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

use Fonts\GoogleFonts;

$googleAPIKey = 'my-api-key';

$fonts = new GoogleFonts($googleAPIKey);

列出字体

您可以使用3种不同的方法列出字体(getFontsByWeight($weight), getFontsBySubset($subset) 和 getFontsByType($type))。

示例用法

// 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

列出可用类型

您可以使用3种不同的方法列出可用选项(getFontWeights(), getFontSubsets() 或 getFontTypes())。

字体粗细度

PHP
$weights = $fonts->getFontWeights();
print_r($weights);
HTML输出
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 ) 

字体子集

PHP
$subsets = $fonts->getFontSubsets();
print_r($subsets);
HTML输出
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 )

字体类型/分类

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

许可证

本软件采用MIT许可证发布。请阅读LICENSE了解软件可用性和分发信息。