用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3017|回复: 2
收起左侧

[HELP] 关于CI 上传图片后调用两个函数来处理图片的问题

[复制链接]
发表于 2009-11-28 12:04:55 | 显示全部楼层 |阅读模式
详细代码以下,在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();

}
发表于 2009-11-30 16:29:16 | 显示全部楼层
$this->load->library();
这个方法多次调用无效,这个问题我回答过N次了,呵呵。
第二次调用要改成
$this->image_lib->initialize($config);
 楼主| 发表于 2009-11-30 23:57:23 | 显示全部楼层
问题解决了,多谢Hex

本版积分规则