图像没有';在Joomla中调用字体时不会显示


Image doesn't show up when font called within Joomla

我是Joomla dev和php的新手,所以如果我在做一些愚蠢的事情,请告诉我!

我正在创建一个证书,在用户完成带有姓名、日期等的测试后打印。我已经显示了图像和文本,但当我添加字体时,什么都不会显示。

这是我正在使用和工作的基本脚本(背景图像和字体工作):

$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和imagefttext,没有扩展,有扩展,上面链接的一堆东西,结果都一样。有什么想法吗?我在猜测(并希望!)什么愚蠢的事情?

在PHP中处理文件时,如果使用JURI,则应使用JPATH_。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。但实际上这是错误的做法,因为它是一个本地文件。

路径是我存在的祸根!

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