PHP字体高度功能不起作用

时间:2017-02-16 18:18:05

标签: php

我尝试执行以下php代码,但它总是返回1.如何修复此问题?

    <?php
    $font_size = 4;
    $height = imagefontheight($font_size);
    echo $height;
    ?>

1 个答案:

答案 0 :(得分:2)

让我们试着了解imagefontheight函数的工作原理。

功能签名

for (int n = 0; n < 20; ++n)

内置字体

对于latin2编码中的内置字体,可以是1,2,3,4,5(其中较大的数字对应较大的字体)。

字体映射如下所示:

int imagefontheight ( int $font )

外部字体

你也可以使用imagefontheight()和imageloadfont()来找到外部字体的高度。

Font height: 8 for inner font 1
Font height: 13 for inner font 2
Font height: 13 for inner font 3
Font height: 16 for inner font 4
Font height: 15 for inner font 5

您的代码实际上在做什么?

// Load a .gdf font
$font = imageloadfont('anonymous.gdf');
echo 'Font height: ' . imagefontheight($font);

您使用编号为$font_size = 4; $height = imagefontheight($font_size); echo $height; 的内部字体并获取其高度。这等于4。此值可以在另一个环境中更改,但代码将始终返回常量。