【发布时间】:2012-03-08 07:21:56
【问题描述】:
我正在设计自己的 PHP MVC
其中任何库文件都可以通过以下步骤使用:
加载文件
$this->registry->load->lib('Image');从文件
$this->registry->Image->anyMethod();访问方法
第一行加载位于lib 文件夹中的文件Image.php 并返回instance
如$this->registry->Image
然后使用该实例,文件中的方法anyMethod() 可以作为$this->registry->Image->anyMethod(); fromController 访问
问题是,我无法输出任何图像!
如果从Controller 访问,以下代码不起作用,但如果直接使用则有效!
代码取自http://in2.php.net/imagettftext
public function anyMethod()
{
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
}
请帮忙,我卡住了。
注意:在 imagepng($im); 之前添加 ob_clean(); 似乎有效,但图像上没有文字。
【问题讨论】:
-
也许您的
Controller也发送了一些与您的header('Content-Type: image/png')不兼容的标头信息?
标签: php model-view-controller image-processing controller gd