2011-10-03 86 views
0

我試過下面的代碼在codeigniter中裁剪圖像,但它沒有工作。可能是我錯過了分鐘的事情。助手已加載,並且圖像也存在 的代碼是Codeigniter圖像不裁剪

public function cropAndSave(){ 
        $config['image_library'] = 'gd2'; 
        $config['allowed_types'] = 'gif|jpg|png'; 
        $config['source_image'] = './img-lab/xxx.jpg'; 
        $config['create_thumb'] = true; 
        $config['maintain_ratio'] = false; 
        $config['width'] = 150; 
        $config['height'] = 190; 
        $config['new_image'] = "thumb_shahid.jpg"; 
        $this->load->library('image_lib', $config); 
        $this->image_lib->resize(); 
        echo ' 
        <script> 
         window.parent.location="'. base_url().'" 
        </script> 
        '; 
} 
+0

無論錯誤顯示 –

+0

的某些其它代碼/上下文會有幫助。例如,你在做什麼!$ this-> image_lib-> crop()檢查?我也想象一下,mypic.jpg不會是你圖片的完整路徑。 – simnom

+0

您是否啓用了完整的日誌記錄/調試功能?你還使用什麼圖形庫?它沒有被定義爲'gd2'?等等;你需要安裝該模塊才能使用它,幫助者只是'幫助'使它更容易做到。 – Jakub

回答

1

調用initialize()功能,而不是load()因爲你的圖像庫已經加載

public function cropAndSave(){ 
         $config['image_library'] = 'gd2'; 
         $config['allowed_types'] = 'gif|jpg|png'; 
         $config['source_image'] = './img-lab/xxx.jpg'; 
         $config['create_thumb'] = true; 
         $config['maintain_ratio'] = false; 
         $config['width'] = 150; 
         $config['height'] = 190; 
         $config['new_image'] = "thumb_shahid.jpg"; 
         $this->image_lib->initialize($config); 
         $this->image_lib->resize(); 
         echo ' 
         <script> 
          window.parent.location="'. base_url().'" 
         </script> 
         '; 
    } 
+0

太棒了!有效。謝謝 –