【发布时间】:2011-12-29 15:18:09
【问题描述】:
在/lib/Helper.class.php:
class Helper
{
//... some functions
static public function createImage( $src_image, $params)
{
$vars=array();
foreach(array('angle'=>0,'font'=>'dejavu','font_size'=>20,'line_spacing'=>1.5,'preset'=>'BRCA','color'=>array(0,0,0),'text'=>'default text') as $key=>$value):
$vars[$key]= array_key_exists($key, $params)?$params[$key]:sfConfig::get('app_default_poster_'.$key, $value);
endforeach;
extract($vars);
$interval= $font_size*$line_spacing;
$x=0;
$y=0;
$img_color = imagecolorallocate($src_image, $color[0], $color[1], $color[2]);
$lines=explode("\n", $text);
putenv('GDFONTPATH='.join(':',sfConfig::get('app_font_path')));
$fontname=$font.'.ttf';
foreach($lines as $i=>$line):
imagettftext($src_image, $font_size, $angle, $x, $y+($i+1)*$interval, $img_color, $fontname, $line);
endforeach;
return $src_image;
}
static public function createPoster( $params)
{
$im= imagecreatefromjpeg(sfConfig::get('sf_web_dir').'/images/'.$params['preset'].'.jpg');
return self::createImage($im, $params);
}
static public function createSidetape( $params)
{
$im= imagecreatetruecolor(sfConfig::get('app_sidetape_width'),sfConfig::get('app_sidetape_height'));
$bg= imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0,0,$bg);
return self::createImage($im , $params);
}
}
在我的actions.class.php(某些模块)中
public function executePreview(sfWebRequest $request)
{
$this->getResponse()->setHttpHeader('Content-type', 'image/jpeg');
$this->setLayout(false);
$img2=Helper::createPoster($request->getGetParameters());
imagejpeg($img2, NULL, 10);
return sfView::NONE;
}
现在当我打开 /module/preview?text=Some+Text&preset=notice 时,我看不到正确的图像,但它的二进制数据以及警告:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/weblog/apps/backend/modules/poster/actions/actions.class.php:253) in /var/www/symfony/lib/response/sfWebResponse.class.php on line 336 Warning: Cannot modify header information - headers already sent by (output started at /var/www/weblog/apps/backend/modules/poster/actions/actions.class.php:253) in /var/www/symfony/lib/response/sfWebResponse.class.php on line 357
另一方面,如果我在executePreview 中将$img2=Helper::createPoster($request->getGetParameters()); 更改为$img2=Helper::createSidetape($request->getGetParameters());,我会看到图像。为什么?
这有什么问题?
【问题讨论】:
标签: php symfony1 http-headers