用自己的字体渲染php图像 [英] Render php image with own font

查看:155
本文介绍了用自己的字体渲染php图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use a own font (True Type) in this code:

<?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。

How can i change the font in: Open Sans Semibold? The path is ../fonts/opensans_semibold_macroman/OpenSans-Semibold-webfont.ttf.

推荐答案

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

Do not use imagestring function use imagettftext, this function allow use TTF fonts.

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

这篇关于用自己的字体渲染php图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆