2012-07-23 40 views
-1
/*create watermark*/ 

    // Create the image 
    $im = imagecreate(460, 50); 

    // Create some colors 
    $grey = imagecolorallocate($im, 230, 231, 232); 
    $dark_grey = imagecolorallocate($im, 128, 130, 133); 

    // The text to draw 
    $text = "foobar"; 

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

$font = 'Tondu_beta'; 



    // Add the text 
    imagettftext($im, 15, 0, 15, 35, $dark_grey, $font, $text); 


    $wm_w = imagesx($im); //get width 
    $wm_h = imagesy($im); //get height 

    $wmresource = $im; //watermark resource 

//imagejpeg($wmresource); 

/*end watermark*/ 

字体文件是Tondu_Beta.ttf。上面的代码在我的本地机器上工作得很好,但它只是在上传到活动服务器后给了我一个灰色框。这里有什么问题?谢谢^^imagettftext()不起作用

更新:我记得它给了我这个错误:Could not find/open font bla.bla..bla...

+0

检查错误日志,看看。 – ceejayoz 2012-07-23 17:31:23

+0

也许你的现场服务器没有字体?... – Palladium 2012-07-23 17:33:33

+0

脚本是否知道要在该文件夹中查找字体? – Palladium 2012-07-23 17:35:13

回答

0

的错误是不言自明的。您的实时服务器没有安装有问题的字体(Tondu_Beta.ttf)。将字体安装到服务器上,或者选择服务器具有的字体。

0

直起doc

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.

When using versions of the GD library lower than 2.0.18, a space character, rather than a semicolon, was used as the 'path separator' for different font files. Unintentional use of this feature will result in the warning message: Warning: Could not find/open font. For these affected versions, the only solution is moving the font to a path which does not contain spaces.

In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems.

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

// Name the font to be used (note the lack of the .ttf extension) 
$font = 'SomeFont'; 
?> 
+0

我的代码是否已经有你的代码?我的GD版本是2.0.34 – siaooo 2012-07-23 17:51:07

+0

啊,我错过了。 。 。如果是这样的话,我会同意其他人的看法,并且字体文件名中的大小写区别就是gotcha。 。 。 – ernie 2012-07-23 17:53:21

1

尝试使用

"./Tondu_beta.ttf" 

工作对我来说,当两者字体和PHP文件是在根目录下