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

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度