【发布时间】:2017-07-13 11:57:28
【问题描述】:
如何制作 CodeIgniter 缩略图?我在 CodeIgniter 中使用图像调整大小功能,但我不希望调整图像大小。我希望图像是所有产品页面上的小缩略图,并且当我转到产品详细信息页面时我希望图像很大,但我不知道该怎么做..
所以当我进入我的产品详情页面时,图片和缩略图一样小,但我希望它更大。
一些信息: 我存放图片的表格列:product_foto
我存放图片的图片文件夹:上传
This is my upload function in my controller file:
public function upload(){
$this->load->library('upload');
$this->load->library('image_lib');
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name']= true;
$this->upload->initialize($config);
if(!$this->upload->do_upload('userfile')){
$error = array('error'=>$this->upload->display_errors());
$this->load->view('product_form', $error);
}else{
$data = $this->upload->data();
$config['image_library'] = 'gd2';
$config['source_image'] = './upload/'.$data["raw_name"].$data['file_ext'];
$config['new_image'] = './upload/'.$data["raw_name"].$data['file_ext'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 170;
$config['height'] = 130;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->db->insert('products', array(
'product_foto' => $data["raw_name"].$data['file_ext'],
'product_naam' => $this->input->post('product_naam'),
'product_beschrijving' => $this->input->post('product_beschrijving'),
'product_categorie' => $this->input->post('product_categorie'),
'ophaal_plaats' => $this->input->post('ophaal_plaats'),
'date_created' => date('Y-m-d'),
'date_updated' => date('Y-m-d')
));
$data['img'] = base_url().'/upload/'.$data["raw_name"].$data['file_ext'];
header('location:https://kadokado-ferran10.c9users.io/Product/');
}
如您所见,我将图片的大小更改为 170 x 130 宽度,但我只希望缩略图上的大小而不是普通图片上的大小。
【问题讨论】:
标签: php codeigniter codeigniter-3