简体   繁体   English

增加php字体大小

[英]Increase php font size

I am trying to create an image by using PHP. 我正在尝试使用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. 我只能通过使用imagestring函数来显示文本,但是此函数仅允许最大5的字体大小。事实证明,这对我来说太小或太小。 Then, I learned you can have text as big as you want on your image by using imagettftext function. 然后,我了解到,通过使用imagettftext函数,可以在图像上显示所需大小的文本。 This function doesn't work for me at all. 此功能对我根本不起作用。 I found this code in another stackoverflow question while I was researching on this issue. 在研究此问题时,我在另一个stackoverflow问题中找到了此代码。

<?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? 这段代码出了什么问题?还有哪些其他选项可用于增加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. 我什至从计算机上将Microsoft字体类型上传到服务器,仍然得到相同的结果。

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. 更新我忘了提到我实际上确实将字体类型arial.ttf从我的计算机传输到服务器,并转移到了所有PHP文件所在的文件夹中。

From the docs 来自文档

fontfile The path to the TrueType font you wish to use. fontfile您要使用的TrueType字体的路径。

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. 根据PHP使用的GD库版本,当fontfile不是以/开头时,.ttf将被附加到文件名,并且库将尝试沿着库定义的字体路径搜索该文件名。

Remove the .ttf or add an absolute path 删除.ttf或添加绝对路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM