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

时间:2016-03-01 10:55:39

标签: php codeigniter

我的问题是我想重新调整我的图像大小,即时搜索codeigniter如何调整图像大小,但我发现所有这些都使用了image_lib()。我没有使用image_lib()所以我对如何在不使用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');

}

1 个答案:

答案 0 :(得分:1)

当CI提供内置库时,您不必下载和配置第三方image_resize库!! ....如果您想这样做,请按照以下步骤操作:

步骤1:使用此单行导入库...

$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步:这就是所有......根据您的需要可能需要进行少量修改。如有任何问题,或者您不知道图书馆的工作方式,请访问此链接..

Official ellislab guideline