douguai6716 2014-12-03 20:12
浏览 322
已采纳

增加php字体大小

I am trying to create an image by using PHP. This image is supposed to have text on it. I am only able to get the text displayed by using imagestring function, but this function only allows font size of upto 5. As it turns out, this is too small or tiny of a font for me. Then, I learned you can have text as big as you want on your image by using imagettftext function. This function doesn't work for me at all. I found this code in another stackoverflow question while I was researching on this issue.

<?php
$image = imagecreate(400,300);
$blue = imagecolorallocate($image, 0, 0, 255);
$white = ImageColorAllocate($image, 255,255,255);

if(!isset($_GET['size'])) $_GET['size'] = 44;
if(!isset($_GET['text'])) $_GET['text'] = "Hello, world!";

// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'arial.ttf';

imagettftext($image, $_GET['size'], 15, 50, 200, $white, $font, $_GET['text']);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?> 

I see funny faces and weird characters on the browser when I call it up. What is wrong this code and what other options available for increasing font size in PHP?

UPDATE After much research on this, I've tried all the suggestions and answers that were given online for this issue, but still it won't display image. I added ./ in front of the font type string. I even uploaded a Microsoft font type from my computer to the server and still ended up with the same result.

UPDATE I did forget to mention that I actually did transfer font type arial.ttf from my computer to the server into the folder where all of my php files resides.

  • 写回答

1条回答 默认 最新

  • donglu1913 2014-12-04 14:32
    关注

    From the docs

    fontfile The path to the TrueType font you wish to use.

    Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.

    Remove the .ttf or add an absolute path

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题