2017-10-11 192 views
-3

如何調整圖像的高度和寬度在PHP笨

public function resize() { 
 
\t \t $config['width'] = $this->input->post('width'); 
 
\t \t $config['height'] = $this->input->post('height'); 
 
\t \t $config['maintain_ratio'] = TRUE; 
 
\t \t $config['source_image'] = './uploads1/book.jpg'; 
 
\t \t $config['new_image'] = './uploads1/book_new.jpg'; 
 
\t \t $this->image_lib->initialize($config); 
 
\t \t $resize = $this->image_lib->resize(); 
 
\t \t 
 
\t }

如何調整在PHP笨圖像的高度和寬度,只有高度沒有調整正確,但寬度我得到

+0

添加您的代碼並解釋您在這樣做時面臨的問題。 –

+0

您是否收到錯誤?你沒有給我們太多的信息來在這裏工作。 – flauntster

+0

歡迎使用堆棧溢出。你已經嘗試過這麼做了嗎?請回顧[預計需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users)。堆棧溢出不是一種編碼服務。您需要研究您的問題,並嘗試在發佈之前親自編寫代碼。如果遇到某些特定問題,請返回幷包含[最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)以及您嘗試的內容摘要,以便我們提供幫助。 – Sand

回答

0
$this->load->library('image_lib'); 
if (!empty($_FILES['advert_image'])) { 

       $filename = substr(md5(time()), 0, 28) . strrchr($_FILES['advert_image']['name'], '.'); 
       $config['upload_path'] = 'public/events/images/'; 

       $config['allowed_types'] = 'jpg|jpeg|png|JPG|JPEG|PNG|BMP|bmp|gif|GIF'; 
       $config['file_name'] = $filename; 

       $config['is_image'] = true; 

       $this->load->library('upload', $config); 
       $this->upload->initialize($config); 
       //$this->upload->do_upload('advert_image'); 
       //start resize image 
       if (!$this->upload->do_upload('advert_image')) { 
        echo "error" . count; 
       } else { 
        $image_data = $this->upload->data(); 

        $configer = array(
         'image_library' => 'gd2', 
         'source_image' => $image_data['full_path'], 
         'maintain_ratio' => TRUE, 
         'width' => 480, 
         'height' => 480, 
        ); 
        $this->image_lib->clear(); 
        $this->image_lib->initialize($configer); 
        $this->image_lib->resize(); 
       } 
       //end resize 
       $profile_pic = isset($filename) ? $filename : ""; 
      } 
+0

這是代碼不工作在我的控制器 –

0

您必須在設置配置值後初始化庫以使用它:

$this->load->library('image_lib', $config); 

確保高度的輸入值不是空的!

相關問題