用自己的字体渲染php图像

时间:2014-10-19 19:28:45

标签: php image fonts rendering true-type-fonts

我想在此代码中使用自己的字体(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。

1 个答案:

答案 0 :(得分:0)

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

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