2017-04-27 90 views
0

我想在我的網站上傳大圖像。我想減小使用codeigniter的人的大小。所以我在做這個代碼Codeigniter圖像壓縮不起作用

function upload_image($data) { 
    $config['upload_path'] = './temp/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = 10000; 
    $this->load->library('upload', $config); 
    if (!$this->upload->do_upload('image')) { 
     $error = array('error' => $this->upload->display_errors()); 
     pre($error); 
    } else { 
     $config = array(); 
     $data = array('upload_data' => $this->upload->data()); 
     $config['image_library'] = 'gd'; 
     $config['source_image'] = './temp/' . $data['upload_data']['file_name']; 
     $config['create_thumb'] = FALSE; 
     $config['maintain_ratio'] = TRUE; 
     $config['quality'] = 50; 
     $config['new_image'] = './temp/' . $data['upload_data']['file_name']; 
     $this->load->library('image_lib', $config); 
     $this->image_lib->resize(); 

     pre($data); 
    } 
} 

但是圖像沒有被壓縮。原始和上傳的大小是相同的。我錯在哪裏?

+1

使用此參數與質量PARAM那麼它會降低圖像 $配置[大小」寬度'] = 75; $ config ['height'] = 50; –

回答

0

也許存在錯誤。檢查是否存在錯誤:

if (!$this->image_lib->resize()){ 
    echo $this->image_lib->display_errors(); 
} 

注意:使用GD2作爲庫(默認值是GD2):

$config['image_library'] = 'gd2';