1

我有在codeigniter中上传图片的功能,在这里我可以上传任何图片,但是当我需要在我的网站上显示这些图片时,我会使用这个代码:-

<img src="uploads/<?=$user->pic?>" width="250px" height="200px" />

如果图像最大超过 250,则图像显示不佳。

所以我怎么能为我的照片做拇指。

public function do_upload($field) {
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';

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

    if (!$this->upload->do_upload($field)) 
    {
        $error = array('error' => $this->upload->display_errors());
        return $error;
    } 
    else
    {
      $updata =$this->upload->data();
      $data = $updata['raw_name'].$updata['file_ext'];
      return $data;
    }
}
4

1 回答 1

1

在这里,只需指定 file_path 就可以了(+宽度/高度),更多选项请看这里

public function resize_image($file_path, $width, $height) {

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

    $img_cfg['image_library'] = 'gd2';
    $img_cfg['source_image'] = $file_path;
    $img_cfg['maintain_ratio'] = TRUE;
    $img_cfg['create_thumb'] = TRUE;
    $img_cfg['new_image'] = $file_path;
    $img_cfg['width'] = $width;
    $img_cfg['quality'] = 100;
    $img_cfg['height'] = $height;

    $this->image_lib->initialize($img_cfg);
    $this->image_lib->resize();

}
于 2013-09-21T12:12:08.617 回答