略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::queryFonts

2024-04-28

Imagick::queryFonts

(PECL imagick 2, PECL imagick 3)

Imagick::queryFontsReturns the configured fonts

说明

public static Imagick::queryFonts(string $pattern = "*"): array

Returns the configured fonts.

参数

pattern

The query pattern

返回值

Returns an array containing the configured fonts.

错误/异常

错误时抛出 ImagickException。

范例

示例 #1 Imagick::queryFonts()

<?php
        $output 
'';
        
$output .= "Fonts that match 'Helvetica*' are:<br/>";

        
$fontList = \Imagick::queryFonts("Helvetica*");
 
        foreach (
$fontList as $fontName) {
            
$output .= '<li>'$fontName."</li>";
        }

        return 
$output;

?>
add a noteadd a note

User Contributed Notes 1 note

up
3
Stefano
5 years ago
If you want to create a graphical output of the  configured/embedded fonts

function outputFont( $fontName = 'Courier' ) {
    $image = new Imagick();
    $draw = new ImagickDraw();

    $draw->setGravity( Imagick::GRAVITY_CENTER );
    $draw->setFont( $fontName );
    $draw->setFontSize( 12 );
    $draw->setFillColor( 'black' );

    $image->newImage( 300, 20, new ImagickPixel( 'lightblue' ) );
    $image->annotateImage( $draw, 0, 0, 0, $fontName );
    $image->setImageFormat( 'png' );

    $src = 'data: ' . mime_content_type( $image ) . ';base64,' . base64_encode( $image );
    return '<img src="' . $src . '"> ' . $fontName . '<br>';
}

echo '<style>img{vertical-align: middle; margin-bottom: 1px;}</style>';
$fontList = \Imagick::queryFonts( '*' );
foreach ( $fontList as $fontName ) {
    echo outputFont( $fontName );
}

官方地址:https://www.php.net/manual/en/imagick.queryfonts.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3