Home > Backend Development > PHP Tutorial > sina-app-engine - 新浪sae 使用imagettftext总是提示 imagettftext() [function.imagettftext]: Could not find/open font in weather.php on line 64

sina-app-engine - 新浪sae 使用imagettftext总是提示 imagettftext() [function.imagettftext]: Could not find/open font in weather.php on line 64

WBOY
Release: 2016-06-06 20:50:20
Original
1362 people have browsed it

本地测试没有问题,上传到sae上的时候就会这样报错

代码:

<code class="lang-php">    <?php $font1='meteocons.ttf';
    imagettftext($img, 90, 0, 40, 147, $textcolor, $font1, $tq_icon);
    ?>
</code>
Copy after login
Copy after login

错误为:

<code class="lang-html">    Warning: imagettftext() [function.imagettftext]: Could not find/open font in weather.php on line 64
</code>
Copy after login
Copy after login

stackoverflow上有篇解决这个的提问:http://stackoverflow.com/questions/10366679/warning-imagettftext-function-imagettftext-could-not-find-open-font-in-ho 按照他的方法,前面加/没用,又说Linux下要使用绝对路径,sae上怎么使用绝对路径?

回复内容:

本地测试没有问题,上传到sae上的时候就会这样报错

代码:

<code class="lang-php">    <?php $font1='meteocons.ttf';
    imagettftext($img, 90, 0, 40, 147, $textcolor, $font1, $tq_icon);
    ?>
</code>
Copy after login
Copy after login

错误为:

<code class="lang-html">    Warning: imagettftext() [function.imagettftext]: Could not find/open font in weather.php on line 64
</code>
Copy after login
Copy after login

stackoverflow上有篇解决这个的提问:http://stackoverflow.com/questions/10366679/warning-imagettftext-function-imagettftext-could-not-find-open-font-in-ho 按照他的方法,前面加/没用,又说Linux下要使用绝对路径,sae上怎么使用绝对路径?

<code class="lang-php"><?php echo dirname(__FILE__);
</code></code>
Copy after login

看看输出。你可以得到绝对路径。

选用字体文件,的确是需要使用绝对路径。

一般都会有一个类似common.inc.php这样的文件,作用就是公共加载文件,功能就是连接数据库、定义网站在服务器的根目录的绝对路径等。

<code class="lang-php">// /common.inc.php
<?php define('__PATH__',dirname(__FILE__));
</code></code>
Copy after login

```php // /api/weather.php require_once '../common.inc.php';

$fontfile = PATH.'/font.ttf'; $gd = imagecreatefromgd(); imagettftext ( $gd , $size , $angle , $x , $y , $color , $fontfile , $text )

?> ```

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template