Render php image with own font

。_饼干妹妹 提交于 2019-12-25 00:03:13

问题


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);
?>

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


回答1:


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);


来源:https://stackoverflow.com/questions/26454455/render-php-image-with-own-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!