2012-07-27 77 views
0

我是Joomla dev和php的新手,如果我正在做一些愚蠢的事情,请告诉我!当Joomla内调用字体时,图片不显示

我在用户用他们的名字,日期等完成测验后创建了要打印的证书。我已将图像显示出来并显示文本,但是当我添加字体时什么也没有显示出来。

下面是我使用的基础脚本和作品(背景图像和字体的工作):

$image_file = 'images/certificate_page.png'; 
$my_img = imagecreatefrompng ($image_file); 
$font_size_big = 24; 
$text_colour = imagecolorallocate($my_img, 0, 0, 0); 
$font_file = 'FelipaRegular.ttf'; 

imagefttext($my_img, $font_size_big, 0, 5, 75, $text_colour, $font_file, "test with font"); 
imagestring($my_img, 4, 30, 25, "test without font", $text_color); 

header("Content-type: image/png"); 
imagepng($my_img); 

imagecolordeallocate($text_color); 
imagedestroy($my_img); 

当我试图内的Joomla应用它的问题开始。

<img src="<?php echo JURI::root().'index.php?tmpl=certgenerator&quizmod='.$quizmod.'' ?>" /> 

和文件生成器(certgenerator.php):

defined('_JEXEC') or die; 
require_once("includes/variables_certificate.php"); 

$image_file = JURI::root().'templates/'.$this->template.'/images/certificate_page.png'; 
$my_img = imagecreatefrompng ($image_file); 
$font_size_big = 24; 
$text_color = imagecolorallocate($my_img, 0, 255, 0); 
$font_file = 'FelipaRegular.ttf'; 

imagefttext($my_img, $font_size_big, 0, 55, 75, $text_color, $font_file, "why u no work"); //if commented out image displays but not font obviously, as it's written now it returns a blank page 
imagestring($my_img, 4, 30, 25, "works", $text_color); //works but doesn't include font 

header("Content-type: image/png"); 
imagepng($my_img); 

imagecolordeallocate($text_color); 
imagedestroy($my_img); 

参考:

http://php.net/manual/en/function.imagettftext.php 

我已经试过imagettftext我是从这样的一个模板内调用它vs imagefttext,没有扩展名,带有扩展名,来自上面链接的一堆东西,所有相同的结果。有任何想法吗?我在猜测(并希望!)一些愚蠢的东西?

+1

有效的字体文件在正确的目录中具有正确的权限? – 2012-07-27 04:56:04

+0

这两个脚本与字体位于同一目录中;尽管它可能是Joomla中的路径问题。我试过了一堆不成功的路径 - Joomla会需要一个特定的路径或位置吗? – Gisto 2012-07-27 12:12:12

回答

2

在你的PHP使用文件时,你应该使用JPATH_而不是JURI。 JURI用于生成http URI。

$image_file = JURI::root().'templates/'.$this->template.'/images/certificate_page.png'; 

应该

$image_file = JPATH_SITE.'/templates/'.$this->template.'/images/certificate_page.png'; 

不知道这是否是问题,你的代码可以很好地工作,因为我有一个鬼鬼祟祟的怀疑imagecreatefrompng()接受HTTP。但实际上这是一个错误的方式去做,因为它是一个本地文件。

+0

是的,就是这个问题 - 我打败了你,但是这里是支票:) – Gisto 2012-07-27 14:45:43

0

路径是我存在的祸根!

$font_file = JPATH_SITE.'/templates/'.$this->template.'/images/font/FelipaRegular.ttf';