用自己的字体渲染php图像


Render php image with own font

我想在这段代码中使用自己的字体(True Type):

<?php
header("Content-type: image/png");
// Email adres renderen
$email    =    "mail@mail.nl";
$length    =    (strlen($email)*8);
$im = @ImageCreate ($length, 20)
     or die ("Kan geen nieuwe afbeelding genereren");
$background_color = ImageColorAllocate ($im, 53, 88, 121); // Container BG: 53,88,121
$text_color = ImageColorAllocate ($im, 194, 212, 229);
imagestring($im, 3,5,2,$email, $text_color);
imagepng ($im);
?>

如何更改:Open Sans Semibold中的字体?路径是/fonts/opensans_semibold_macroman/opensans-semibold-webfont.ttf.

不使用imagestring函数使用imagettftext,此函数允许使用TTF字体。

$font_file = "../fonts/opensans_semibold_macroman/OpenSans-Semibold-webfont.ttf";
imagettftext ($im, 3, 0, 5, 2, $text_color, $font_file, $email);