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

[已解决] 图片处理类,不能处理多个图片

[复制链接]
发表于 2009-12-15 17:24:49 | 显示全部楼层 |阅读模式
怎样才能做到,处理多个图片.
或者是处理同一个图片2次以上

比如一个图片,我要生成两个不同大小的图片.应该怎么做??
实在没办法了.帮帮忙.....
发表于 2009-12-15 17:30:22 | 显示全部楼层
第一次用$this->load->library('image_lib', $config);
第二次用$this->image_lib->initialize($config2);
 楼主| 发表于 2009-12-15 17:33:57 | 显示全部楼层
我写成函数了...

//切图
function _Slicing($width,$height,$image,$Newimage,$Thumb=TRUE){
  $config['image_library'] = 'gd2';
  $config['source_image'] = $image;
  $config['new_image'] = $Newimage;
  $config['create_thumb'] = $Thumb;
  $config['maintain_ratio'] = FALSE;
  $config['width'] = $width;
  $config['height'] =$height;
  $this->load->library('image_lib', $config);
  if ( !$this->image_lib->resize()){
   $this->image_lib->clear();
   return $this->image_lib->display_errors();
  }
  else{
   $this->image_lib->clear();
   return true;
  }
}
发表于 2009-12-15 18:01:14 | 显示全部楼层
注意,->load->library()只能用一次,第二次再用load,$config不会改变,相当于你进行了两次相同的操作,第一个图片被第二个覆盖了
 楼主| 发表于 2009-12-15 18:14:34 | 显示全部楼层
谢谢老大.问题解决了... 红色部分老大提醒的是.这样就没问题了...这个初始化.

function _Slicing($width,$height,$imagePath,$NewPath){
  $config['image_library'] = 'gd2';
  $config['source_image'] =$imagePath;
  $config['new_image'] =$NewPath;
  $config['create_thumb'] = FALSE;
  $config['maintain_ratio'] = FALSE;
  $config['width'] = $width;
  $config['height'] =$height;
  $this->load->library('image_lib', $config);
  $this->image_lib->initialize($config);
  if ( !$this->image_lib->resize()){
   return $this->image_lib->display_errors();
  }
  else{
   $this->image_lib->clear() ;
   return ture;
  }
}
发表于 2009-12-15 19:03:10 | 显示全部楼层
多文件上传类,论坛有,自己搜一下。
发表于 2009-12-17 11:46:33 | 显示全部楼层
收藏了,遇到这个功能以后直接用,哈哈!

本版积分规则