包含该方法的类如下:
<?php
class renderText {
function text_to_image( $text, $width, $height, $image_file ) {
$fonts_dir = 'path/to/directory/in/which/SreeKrushnadevaraya.ttf/is/located/';
$ret = mb_language('uni');
mb_internal_encoding('UTF-8');
header('Content-type: image/gif');
$font = $fonts_dir.'SreeKrushnadevaraya.ttf';
error_log("=before imagecrttrucolour",3,'path/to/frontend_dev.log');
$im = imagecreatetruecolor( $width, $height );
error_log("=after imagecrttrucolour",3,'path/to/frontend_dev.log');
$white = imagecolorallocate( $im, 255, 255, 255 );
$black = imagecolorallocate( $im, 0, 0, 0 );
imagefilledrectangle( $im, 0, 0, $width, $height, $white );
imagettftext( $im, 10, 0,10 ,30, $black, $font, $text );
$image_file = '/tmp/'.date('YmdHis').$width.$height.'.gif';
imagegif( $im, $image_file );
imagedestroy( $im );
return $image_file;
}
}
?>
以下代码添加到 symfony 以及本地脚本中。它在本地脚本中运行良好,但在 symfony 中失败:
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('path/to/directory/in/which/SreeKrushnadevaraya.ttf/is/located/'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SreeKrushnadevaraya';
该方法是这样调用的:
$image_file = '/tmp/'.date('YmdHis').'260'.'x'.'32.gif';
$rendered_text = renderText::text_to_image($this->getRequestParameter('caption_unicode'), 240, 32, $image_file);
php 版本:PHP 5.3.6
symfony 版本 1.0.22