在codeigniter中不使用image_lib调整图像大小

问题描述:

我的问题是我想重新调整图像大小,即时搜索codeigniter如何重新调整图像大小,但我发现它们都使用image_lib()。我不使用image_lib(),所以我就如何重新尺寸混淆了图像,而无需使用image_lib()..在codeigniter中不使用image_lib调整图像大小

这里是我的是CI_Controller

public function fileUpload() 
     { 

    $title = $this->input->post('title'); 
      $attachment_file=$_FILES["attachment_file"]; 
      $output_dir = "images/header/"; 
      $fileName = $_FILES["attachment_file"]["name"]; 
    move_uploaded_file($_FILES["attachment_file"]["tmp_name"],$output_dir.$fileName); 

    $this->person->save($title, $fileName,'slider'); 

} 

你没有下载和配置

STEP 1:如果你想要做的只是按照以下步骤时,CI提供了内置的库那!! ....第三方image_resize库导入库使用该单线...

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

第2步:根据你的代码现在,更改如下

public function fileUpload() 
     { 

    $title = $this->input->post('title'); 
    $sourcePath = $_FILES["attachment_file"]['tmp_name']; // source path of the file; 
    $new_img = time(). '_' .$_FILES["attachment_file"]['name']; 
    $targetPath = 'images/header/' . $new_img; // Target path where file is to be stored 
    move_uploaded_file($sourcePath, $targetPath); // Moving Uploaded file 


    $config_resize['image_library'] = 'gd2'; 
    $config_resize['create_thumb'] = TRUE; 
    $config_resize['maintain_ratio'] = TRUE; 
    $config_resize['master_dim'] = 'height'; 
    $config_resize['quality'] = "100%"; 
    $config_resize['source_image'] = $targetPath; 
    $config_resize['height'] = 60; 
    $config_resize['width'] = 60; 
    $config_resize['thumb_marker'] = ''; 
    $config_resize['new_image'] = 'images/header/' . $new_img; 
    $this->image_lib->initialize($config_resize); 
    $this->image_lib->resize(); 

    $uploaded = TRUE; 

    $this->person->save($title, $new_img ,'slider'); 

} 

第3步:这就是所有...它可能需要稍加修改,按您的need.If任何问题,或者你没有任何想法库的工作原理访问此链接..

Official ellislab guideline

+0

谢谢你..你的答案我有很大帮助...它的作品! –

+0

不客气@MGB C – Kunal