2012-04-11 119 views
0

我必須使用php(codeigniter)創建圖像,並需要在瀏覽器中顯示它。我得到了一類喜歡如下在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

什麼錯誤? – cchana 2012-04-11 09:59:48

+1

這是404未找到錯誤的錯誤? – 2012-04-11 10:19:47

+0

錯誤是..圖像「http://localhost/tvc/index.php/get_captcha不能顯示,因爲它包含錯誤 – ramesh 2012-04-11 11:37:44

回答

1

最有可能的錯誤有事情做與verdana.ttf沒有發現......

+0

是的,它的路徑是正確的 – ramesh 2012-04-11 11:48:34