0

私は 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 を試してみましたが、拡張子なし、拡張子あり、上記のリンクからたくさんのものを試しましたが、すべて同じ結果でした。何か案は?私は推測している(そして望んでいる!)何かばかげた?

4

2 に答える 2

2

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を受け入れるという卑劣な疑いがあるので、あなたのコードはうまくいくかもしれません. しかし、それはローカルファイルであるため、実際には間違った方法です。

于 2012-07-27T13:56:41.483 に答える
0

パスは私の存在の悩みの種です!

$font_file = JPATH_SITE.'/templates/'.$this->template.'/images/font/FelipaRegular.ttf';  
于 2012-07-27T13:07:21.087 に答える