在codeigniter中显示创建的图像

时间:2012-04-11 09:56:33

标签: php codeigniter image-processing

我必须使用php(codeigniter)创建一个图像,并需要在浏览器中显示它。我有一个像下面这样的课程

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// class Welcome extends CI_Controller {


    class Get_captcha extends CI_Controller {

 function __construct()
{
    parent::__construct();
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->helper(array('form', 'url'));

}

function index()
{

// header('Content-Type: image/png');
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 = 'verdana.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);


}



    }

当我致电http://localhost/tvc/index.php/get_captcha时,显示错误..

请有人帮助我吗?

由于

1 个答案:

答案 0 :(得分:1)

很可能错误与找不到verdana.ttf有关...