|
详细代码以下,在upload_img() 调用$this->create_thumbnail(); 和$this->img_resize(); 时后者的会失效,两个函数的前后调了后,都是后边哪个函数失效,不知道原因,昐各位高手指点,多谢。
$data_img = $this->upload_img();
private function upload_img(){
$config['upload_path'] = 'base/uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2048';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
echo $this->upload->display_errors();
}else {
$file_info = $this->upload->data();
$this->create_thumbnail($file_info['file_name'],$file_info['image_width'],$file_info['image_height']);
$this->img_resize($file_info['file_name'],$file_info['image_width'],$file_info['image_height']);
$data_img['goods_image'] = $file_info['file_name'];
$data_img['thumb_image'] = 'thumb/'.$file_info['raw_name'] . '_thumb' . $file_info['file_ext'];
return $data_img;
}
}
//缩略图
private function create_thumbnail($file_name,$image_width,$image_height) {
$set_thumb_width = 100;
$set_thumb_height = 75;
$config['image_library'] = 'gd2';
$config['source_image'] = 'base/uploads/' . $file_name;
$config['new_image'] = 'base/uploads/thumb/' . $file_name;
$config['create_thumb'] = TRUE;
//$config['thumb_marker'] = "_{$set_thumb_width}x{$set_thumb_height}_thumb";
$config['maintain_ratio'] = TRUE;
if($image_width > $set_thumb_width or $image_height > $set_thumb_height){
$config['width'] = $set_thumb_width;
$config['height'] = $set_thumb_height;
}
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
unset($config);
$this->image_lib->clear();
}
//调整图像大小
private function img_resize($file_name,$image_width,$image_height) {
$set_width = 800;
$set_height = 600;
$config['image_library'] = 'gd2';
$config['source_image'] = 'base/uploads/' . $file_name;
$config['new_image'] = 'base/uploads/image/' . $file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
if($image_width > $set_width or $image_height > $set_height){
$config['width'] = $set_width;
$config['height'] = $set_height;
}
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
unset($config);
$this->image_lib->clear();
} |
|