2013-10-07 72 views
0

我用動態顏色,字體,按鈕大小創建了表單。 當我提交表單時,按鈕圖像顯示在整個頁面中,我需要顯示在第一頁本身。如何使用Gd庫在codeigniter中顯示動態按鈕?

我控制器代碼:

public function creatorbuton(){ 
    $button_size = $this->input->POST('button_size'); 
    $font_style = $this->input->POST('font_style'); 
    $color_schme = $this->input->POST('color_schme'); 
    $textdisplay = $this->input->POST('textdisplay'); 
    header('content-type: image/png'); 

    //Create our basic image stream 
    //125px width, 125px height 
    $image = imagecreate(120, 60); 

    //Set the background color 
    $blue = imagecolorallocate($image, 150, 50, 105); 

    //Set up another color just to show how the first color declared is used as the background color when we use imagecreate() 
    //Notice how blue is applied to the background, *not* red. 
    $red = imagecolorallocate($image, 150, 200, 10); 

    //$font = myurl.'fonts/arial.ttf'; 
    //$text="Hello"; 
    //imagettftext($image, 20, 0, 11, 21, $red, $font, $text); 
    //save the image as a png and output 
    $result_array['final_image'] = imagepng($image); 

    //Clear up memory used 
    imagedestroy($image); 
    $this->load->view('buttonconfig/buttoncreator',$result_array); 

如何dispaly在buttoncreator視圖頁面的按鈕。當我使用取消註釋此行

imagettftext($image, 20, 0, 11, 21, $red, $font, $text); 

我得到這一行「圖像我的URL無法顯示,因爲它包含錯誤」。

+0

請多加小心,在未來你的代碼的格式。如果您的代碼易於閱讀和理解,則更有可能得到積極的迴應 –

回答

0

我得到的輸出:我的代碼是

public function creatorparam(){ 
    $bg_color="FF8640"; 
    $text_color="C7FFE3"; 
    $button_width =120; 
    $button_height =90; 

    $r_bg = hexdec("0x".substr($bg_color,0,2)); 
    $g_bg = hexdec("0x".substr($bg_color,2,2)); 
    $b_bg = hexdec("0x".substr($bg_color,4,2)); 

    $r_bgt = hexdec("0x".substr($text_color,0,2)); 
    $g_bgt = hexdec("0x".substr($text_color,2,2)); 
    $b_bgt = hexdec("0x".substr($text_color,4,2)); 
    header('content-type: image/png'); 
    $image = imagecreate($button_width, $button_height); 
    $blue = imagecolorallocate($image, $r_bg, $g_bg, $b_bg); 
    $red = imagecolorallocate($image, $r_bgt, $g_bgt, $b_bgt); 
    imagestring($image,18,0,0,$textdisplay,$red); 
    imagepng($image); 
    imagedestroy($image); 
} 
相關問題